Closed
Description
Bug Report
π Search Terms
variable declaration equals implicit any loop
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
interface State {}
declare function initialState(): State | null
declare function nextState(state: State | null): [State] | undefined
export function bar(): void {
let state = initialState()
if (state == null) return
for (;;) {
const [next]: [State] | [] = nextState(state) ?? []
// ~~~~ 'next' implicitly has type 'any' because it does not have a
// type annotation and is referenced directly or indirectly in its own initializer.
state = next!
}
}
Originally reported in: typescript-eslint/typescript-eslint#2248
π Actual behavior
'next' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
If you removestate = next!
or the for (;;)
, the code exhibits the expected behavior.
π Expected behavior
next
is inferred to be type State | undefined
.
Metadata
Metadata
Assignees
Labels
No labels