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
{{ message }}
Repository navigation
Type 'boolean' is not assignable to type 'true' when constructing discriminated union variant #10657
src/option.ts(13,5): error TS2322: Type '{ is_some: boolean; value: number; }' is not assignable to type 'Option<number>'.
Type '{ is_some: boolean; value: number; }' is not assignable to type 'Some<number>'.
Types of property 'is_some' are incompatible.
Type 'boolean' is not assignable to type 'true'.
Adding a cast of the boolean value to type true appears to fix the error:
// working examplevara: Option<number>={is_some: <true>true,value: 1};
I encountered this problem when experimenting with the following function. A version of the code which uses strings as the discriminator works without casts. Another version which uses value: null as the discriminator in the None case also works.
I have something similar in typescript 2.4.2, but it looks like it's only when I have return in a promise. Casting the boolean type to true or false fixes the problem.
Activity
yortus commentedon Sep 1, 2016
Duplicate of #10432. The PR in #10577 should fix this.
deadalusai commentedon Sep 1, 2016
Referenced issue looks to be identical - even the Same code sample. Closing as dupe.
tcoopman commentedon Jul 21, 2017
I have something similar in typescript 2.4.2, but it looks like it's only when I have return in a promise. Casting the boolean type to true or false fixes the problem.