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.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
'index' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
#51659
'index' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
plantain-00
opened this issue
Nov 28, 2022
· 1 comment
This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
⏯ Playground Link
Playground link with relevant code
💻 Code
let children: string | A[] = []
while (typeof children !== 'string') {
const index = children.length - 1
children = children[index].children
interface A {
children: A[] | string
🙁 Actual behavior
'index' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer
🙂 Expected behavior
No error here
Duplicate of #43047. The type of index
depends on the type of children
, the type of children
depends on the type of index
(due to the reassignment).
Just add a type annotation.