Skip to content

Conditional types can't resolve keyof this #21862

Closed
@falsandtru

Description

@falsandtru

cc @ahejlsberg

TypeScript Version: 2.7.0-dev.20180210

Search Terms:

Code

type OldDiff<T extends string, U extends string> = (
  & { [P in T]: P; }
  & { [P in U]: never; }
  & { [x: string]: never; }
)[T];
type NewDiff<T, U> = T extends U ? never : T;
interface A {
  a: 'a';
}
interface B1 extends A {
  b: 'b';
  c: OldDiff<keyof this, keyof A>;
}
interface B2 extends A {
  b: 'b';
  c: NewDiff<keyof this, keyof A>;
}
type c1 = B1['c']; // 'c' | 'b'
type c2 = B2['c']; // 'c' | 'a' | 'b'

Expected behavior:

c2 is 'c' | 'b'.

Actual behavior:

c2 is 'c' | 'a' | 'b'.

Playground Link:

Related Issues:

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