-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 2.4.2
Code
type One = {
kind: true;
foo: string;
}
type Two = {
kind: false;
foo: boolean;
}
type Options = One | Two;
const fn = (options: Options) => { /* ... */ };
const optionsOne = { kind: true, foo: 'bar' };
/**
* ERROR:
* Types of property 'kind' are incompatible.
* Type 'boolean' is not assignable to type 'false'.
*/
fn(optionsOne);
/**
* No Error.
*/
fn({ kind: true, foo: 'bar' })Expected behavior: Should be possible to use true | false to create a discriminated union. It seems like true | false and boolean are not interchangeable.
Actual behavior: TypeScript does not widen the above kind to boolean and thus optionsOne can not be used as input for fn. (That's just my wild guess :-x) It's not possible to use true and false for discriminated unions.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug