π Search Terms
boolean literal type true false assign expression
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEEQBd4GcD2BbEAhDGEAXPAEYFJQB2A3AFB1KogAeUWADkgIzwC88ZDACuIek3it2XEACZ+6bHgrwAPqsEixQA
π» Code
declare let someBool: boolean;
let okay = true;
let weird = someBool || true;
π Actual behavior
weird is assigned the type true, whereas okay is of type boolean.
π Expected behavior
Both variables have the type boolean.
Additional information about the issue
Stumbled upon this while writing facebook/react#33399.
Very unexpected and confusing behavior, I highly doubt it is intended. Couldn't find anything explaining the change in the release notes for TypeScript 4.2, so pretty sure it's an unwanted regression. Please correct me if I'm wrong.