Suppose I have an existing project to which I am adding flow types:
// Original project:
class Foo {
x = 2;
y = 3;
}
class Bar extends Foo {
x;
sum() {
const sum = (this.x || 5) + this.y;
console.log(sum);
}
}
new Bar().sum(); // Logs 8 (5 + 3);
// With types:
class Foo {
x: ?number = 2;
y: number = 3;
}
class Bar extends Foo {
// *
sum() {
const sum: number = (this.x || 5) + this.y;
console.log(sum);
}
}
new Bar().sum(); // Should log 8 (5 + 3);
* I want to say that the Bar class has:
- an
x property whose type is ?number and that is part of the JS code
- an
y property whose type is number and that isn't part of the JS code.
How can I differentiate the two cases?
Suppose I have an existing project to which I am adding flow types:
* I want to say that the
Barclass has:xproperty whose type is?numberand that is part of the JS codeyproperty whose type isnumberand that isn't part of the JS code.How can I differentiate the two cases?