You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A *self-contained* demonstration of the problem follows...// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
Expected behavior: x: string
Actual behavior: 'x' 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 design limitation in the control flow analyzer. Ideally the analyzer would realize that id(f(state)) always has type string regardless of the type of state. However, the analyzer attempts to resolve the type of the expression, which entails resolving the type of state, which entails resolving the type of x (because of the state = x assignment and the back edge of the loop), which leads to a circularity and therefore an implicit any.
TypeScript Version: 3.6.0-dev.20190726
Search Terms:
type inference
Code
Expected behavior:
x: string
Actual behavior:
'x' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
Playground Link:
https://www.typescriptlang.org/play/#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIAoAPALngGcMYtUBzeAH3jVERpGAEozLq6BuAFChIsBCnTY88LMAA8AFQB8xMgu7wFQwRBAYKGKBhBkWINqg6MDfegF5mqVu2BCA7gAssu+ASrIQTngAb0F4eDA8SngieAdZAkQCSiNAziFwlOM4mKEAX0EgA
Related Issues:
The text was updated successfully, but these errors were encountered: