添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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. #51659 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.