Closed
Description
π Search Terms
type inference
explicit type
narrowing
type annotation
π Version & Regression Information
TS version 5.1.6
β― Playground Link
π» Code
async function asyncAssignment(n: number): Promise<number> {
let text: string | null = null;
new Promise((resolve) => {
text = 'some text';
resolve(undefined)
})
await new Promise((resolve) => setTimeout(resolve, 10000));
if (text === null) {
return 0
}
return text.length;
}
π Actual behavior
Typescript narrows text
type to null
and not to string | null
π Expected behavior
Expecting to have string | null
type for text
before explicit type narrowing (if (text === null)
) and string
type after explicit type narrowing
Metadata
Metadata
Assignees
Labels
No labels