Skip to content

Conditional types wrongly work with indexed access and object type (regression) #23800

Closed
@falsandtru

Description

@falsandtru

cc @ahejlsberg

TypeScript Version: 2.9.0-dev.20180501

Search Terms:

Code

type A<T, V> = { [P in keyof T]: T[P] extends V ? 1 : 0; };
type B<T, V> = { [P in keyof T]: T[P] extends V | object ? 1 : 0; };

type a = A<{ a: 0 | 1 }, 0>; // { a: 0; }
type b = B<{ a: 0 | 1 }, 0>; // { a: 1; }

Expected behavior:

type b = B<{ a: 0 | 1 }, 0>; // { a: 0; }

Actual behavior:

type b = B<{ a: 0 | 1 }, 0>; // { a: 1; }

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