Skip to content

identical conditional types not assignable to each other #21756

Closed
@tvald

Description

@tvald

Identical conditional types are not assignable to each other.

TypeScript Version: 2.8.0-dev.20180208

Code

type Foo<T> = T extends string ? boolean : number;
type Bar<T> = T extends string ? boolean : number;
const convert = <T>(value: Foo<T>): Bar<T> => value; // this fails

type Baz<T> = Foo<T>;
const convert2 = <T>(value: Foo<T>): Baz<T> => value; // this passes

Expected behavior:
no errors

Actual behavior:

TypeScript $ ./node_modules/.bin/tsc --noEmit test.ts
test.ts(4,47): error TS2322: Type 'Foo<T>' is not assignable to type 'Bar<T>'.
  Type 'number | boolean' is not assignable to type 'Bar<T>'.
    Type 'number' is not assignable to type 'Bar<T>'.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions