TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
function hello() {
let lastThing = null;
for (let i = 0; i < 2; i++) {
const thing = new Thing(!lastThing ? null : lastThing);
lastThing = thing;
}
}
class Thing {
constructor(public readonly prior: Thing|null) {
}
}
Expected behavior:
Since thing is being defined directly, the compiler should still intuit that it's of type Thing when noImplicitAny is enabled.
Actual behavior:
The compiler doesn't like the nested data reference via the loop and lastThing reference and says thing will be "any" and I have to explicitly define thing as type Thing:
'thing' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
This is a simplified version of the actual code; the existence of a loop and the reference to the prior instance are critical to the actual usage. Repros with the TS playground with noImplicitAny enabled.
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
Expected behavior:
Since thing is being defined directly, the compiler should still intuit that it's of type Thing when noImplicitAny is enabled.
Actual behavior:
The compiler doesn't like the nested data reference via the loop and lastThing reference and says thing will be "any" and I have to explicitly define thing as type Thing:
'thing' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
This is a simplified version of the actual code; the existence of a loop and the reference to the prior instance are critical to the actual usage. Repros with the TS playground with noImplicitAny enabled.