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:
x property whose type is ?number and that is part of the JS codey property whose type is number and that isn't part of the JS code.How can I differentiate the two cases?
y, I'm prefer to strip these codes w/o initial value.
Maybe something like this would work?
class Bar extends Foo {
x: ?number;
declare y: number;
}
Comment syntax would work
class Bar extends Foo {
x: ?number;
/*:: y: number; */
}
we don't want people to be forced to use the comment syntax, so we're going to implement the declare syntax.
Thanks! :heart: :heart: :heart:
We would like to release Babel 8 in March (we don't have an ETA yet, but it won't definitely be in the first half of the month).
In Babel 8, we are going to stop removing uninitialized class fields and so far we have been recommending the comment syntax to migrate to something that will be compatible with the new major version.
If you have any ETA, I could start working on the declare syntax in Babel so that, if you release it in Flow soon, we will be able to ship it in Babel 8.0.0.
Most helpful comment
Thanks! :heart: :heart: :heart:
We would like to release Babel 8 in March (we don't have an ETA yet, but it won't definitely be in the first half of the month).
In Babel 8, we are going to stop removing uninitialized class fields and so far we have been recommending the comment syntax to migrate to something that will be compatible with the new major version.
If you have any ETA, I could start working on the
declaresyntax in Babel so that, if you release it in Flow soon, we will be able to ship it in Babel 8.0.0.