-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Description
π Search Terms
"no-unnecessary-condition", "boolean", "constant", "mutated", "conditional", "timer"
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about setTimeout
β― Playground Link
π» Code
export type IsExact<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
export function assertType<T extends true | false>(_: T) {}
let bool = false;
setTimeout(() => { bool = true; }, 1);
await new Promise(resolve => setTimeout(() => resolve(undefined), 100));
assertType<IsExact<typeof bool, false>>(false);π Actual behavior
Argument of type 'false' is not assignable to parameter of type 'true'. In this case, that means that bool is narrowed to false on line 8.
π Expected behavior
The type of bool should be boolean because it will be true if the timer on line 5 ran and false if it did not. (In practice, with this exact code snippet, it is always true, so it definitely should not be narrowed to false!)
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
No labels