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 = [];
}
}

ais stillnever[], which is the main problem.ais typenever[]...interesting playgroundnever[]is also not desired, but until I can get reproducible behavior that both you and I agree is happening then I'm not inclined to spend a lot of effort on researching it. If you want to change the question to be aboutnever[]that's fine; otherwise you should provide enough info for someone to reproduce it (the playground is also using--noImplicitAnyso that's not the issue)noImplicitAny, it's about not getting the desired array type. Neithernever[]norany[]is good.