I usually have the following code:
class Foo {
foo: SomeType[];
doSomething() {
const a = this.foo = [];
}
}
In this case, a would be any[] or never[] (depends on environment) instead of SomeType[]. If I specify noImplicitAny on those that imply any[], the compiler would throw an error.
I know the below cast fixes the problem, but why can't TypeScript deduce the type from this.foo?
const a: SomeType[] = this.foo = []; // Have to repeat the type again
Reproducible code:
tsconfig.json:
{
"compilerOptions": {
"noImplicitAny": true
}
}
test.ts:
class Foo {
foo: number[];
doSomething() {
const a = this.foo = [];
}
}
