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
typeState<TStateKeysextendsstring=string>={[kinTStateKeys]: boolean|number|string};classFoo<TStateextendsState>{constructor(publicstate: TState){}}constobj=newFoo({a: 1,b: "string",c: true,d: false,// Workarounde: !!false});obj.state.a=2;// No errorobj.state.b="another string";// No error// Accepts only `false`, should accept eitherobj.state.c=false;// TS2322: Type 'false' is not assignable to type 'true'.// Accepts only `true`, should accept eitherobj.state.d=true;// TS2322: Type 'true' is not assignable to type 'false'.// Accepts either booleanobj.state.e=true;// No error
Expected behavior:obj.state.c and obj.state.d accept either boolean.
Actual behavior:obj.state.c and obj.state.d are hard-typed to true and false, respectively.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 3.5.0-dev.20190503
Search Terms: Boolean inference true false
Code
Expected behavior:
obj.state.c
andobj.state.d
accept either boolean.Actual behavior:
obj.state.c
andobj.state.d
are hard-typed totrue
andfalse
, respectively.The text was updated successfully, but these errors were encountered: