Skip to content

Circular reference misdetection (introduced after 3.6.3) #34960

Closed

Description

@orzFly

TypeScript Version: 3.7.2

Search Terms: 7022, referenced directly or indirectly in its own initializer

Code

let items: string[] | null = null;
items = items || [];

for (const row of []) {
  const item = items.find(() => true); // ERROR
  const result = item ? true: false    // ERROR

  switch (result) {

  }
}

Expected behavior:
No error & warnings.

const item: string | undefined
const result: boolean

Actual behavior:

'item' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
'result' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
const item: any
const result: any

Playground Link: Link

It works in 3.6.3 and fails in 3.7.2.

Related Issues:
I think this is not related to #33191 since this introduced after 3.6.3.

Activity

  1. orzFly commented on Nov 6, 2019

    @orzFly
    Author

    More simplified:

    Playground link

    const flag: boolean = false;
    
    for (const row of []) {
      const result = flag ? true: false
      switch (result) { }
    }

    Expected:
    const result: boolean
    const result: false should be ideal as well.

    Actual:

    const result: any
    'result' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
    
  2. ahejlsberg commented on Nov 9, 2019

    @ahejlsberg
    Member

    This is fixed by #35000.

  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions