Skip to content

Conditional types can't resolve keyof this #21862

Closed

Description

cc Anders Hejlsberg (@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:

Activity

  1. falsandtru commented on Feb 12, 2018

    @falsandtru
    ContributorAuthor
  2. ahejlsberg commented on Feb 12, 2018

    @ahejlsberg
    Member

    falsandtru (@falsandtru) Don't know yet, haven't had time to look.

  3. falsandtru commented on Feb 12, 2018

    @falsandtru
    ContributorAuthor

    I see.

  4. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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