-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Description
π Search Terms
any unknown type guard predicate
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about not-bugs
β― Playground Link
π» Code
function isAny(x: unknown): x is any {
return true;
}
const a: unknown = 'foo';
const b: number = a; // compiler error - Type 'unknown' is not assignable to type 'number'.
if (isAny(a)) {
const c: number = a;
}
const d: number = a; // no compiler error, a has been widened to anyπ Actual behavior
if (isAny(a)) changes the type of a from unknown to any both within the if statement and after the if statement.
π Expected behavior
type guards shouldn't change the type of a variable typed as unknown except within their scope
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
No labels