You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functiona(){constvalidFlags=['-a','-b','-c']asconst;functionisFlagValid(flag: string): flag is typeofvalidFlags[number]{returnvalidFlags.includes(flagastypeofvalidFlags[number]);}constflag=Math.random().toString();if(isFlagValid(flag)===false){flag;// stringreturn;}flag;// stringif(!isFlagValid(flag)){flag;// stringreturn;}flag;// typeof validFlags[number]}functionb(){constvalidFlags=['-a','-b','-c']asconst;functionisFlagValid(flag: string): flag is typeofvalidFlags[number]{returnvalidFlags.includes(flagastypeofvalidFlags[number]);}constflag=Math.random().toString();if(isFlagValid(flag)===true){flag;// stringreturn;}flag;// stringif(isFlagValid(flag)){flag;// typeof validFlags[number]return;}flag;// string}
π Actual behavior
The function with a type predicate only limits the type definition of flag if it's used in shorthand syntax !isFlagValid(flag) or isFlagValid(flag) and not the more explicit isFlagValid(flag) === false or isFlagValid(flag) === true.
π Expected behavior
The function with a type predicate limits the type definition of flag regardless of the syntax uses and they both mean the same thing.
The text was updated successfully, but these errors were encountered:
Bug Report
π Search Terms
predicate
type predicate
predicate syntax
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The function with a type predicate only limits the type definition of
flag
if it's used in shorthand syntax!isFlagValid(flag)
orisFlagValid(flag)
and not the more explicitisFlagValid(flag) === false
orisFlagValid(flag) === true
.π Expected behavior
The function with a type predicate limits the type definition of
flag
regardless of the syntax uses and they both mean the same thing.The text was updated successfully, but these errors were encountered: