-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesDomain: Variance RelationshipsThe issue relates to variance relationships between typesThe issue relates to variance relationships between types
Milestone
Description
TypeScript Version: 3.5.0-dev.20190507
Search Terms:
any, unsound, extends, never
Code
// I detect if F is `any` by checking if F extends `never`.
// (F extends never ? true : false) produces `true|false` for `F = any`
// and `false` or `never` for everything else.
type Decider<F> = {
prop: (F extends never ? true : false) extends false ? "isNotAny" : "isAny";
};
let foo!: Decider<string>;
let bar: Decider<any> = foo;
let fooProp: "isNotAny" = foo.prop;
let barProp: "isAny" = bar.prop;
Expected behavior:
Either bar.prop
should have the type "isAny"|"isNotAny"
or foo
should not be assignable to bar
.
Actual behavior:
foo
is assignable to bar
and bar.prop
has the type "isAny"
which is incompatible with foo.prop
's "isNotAny"
.
Playground Link: link
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesDomain: Variance RelationshipsThe issue relates to variance relationships between typesThe issue relates to variance relationships between types