-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
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.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed