Skip to content

Circular reference misdetection (introduced after 3.6.3) #34960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

Closed
orzFly opened this issue Nov 6, 2019 · 2 comments
Closed

Circular reference misdetection (introduced after 3.6.3) #34960

orzFly opened this issue Nov 6, 2019 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@orzFly
Copy link

orzFly commented Nov 6, 2019

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.

@orzFly
Copy link
Author

orzFly commented Nov 6, 2019

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)

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 8, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.0 milestone Nov 8, 2019
@ahejlsberg ahejlsberg self-assigned this Nov 9, 2019
@ahejlsberg
Copy link
Member

This is fixed by #35000.

@ahejlsberg ahejlsberg added the Fix Available A PR has been opened for this issue label Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

No branches or pull requests

3 participants