Skip to content

Conditional types don't distribute union types with property access #22945

Closed
@falsandtru

Description

@falsandtru

cc @ahejlsberg

TypeScript Version: 2.7.0-dev.20180327

Search Terms:

Code

type Id<T> = T;
type Z<T> = Id<T> extends true ? Id<T> : never;
type z = Z<boolean>;
type A<T extends any[]> = T[0] extends true ? T[0] : never;
type a = A<[boolean]>;
type B<T extends {}> = { [P in keyof T]: T[P] extends true ? T[P] : never }[keyof T];
type b = B<[boolean]>;

Expected behavior:

z, a, b is true.

Actual behavior:

z is true but a, b is never.

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions