Skip to content

Inconsistent behaivor between Pick<T,K> and [P in K]: T[K] #28414

Closed
@weichensw

Description

@weichensw

TypeScript Version: 3.2.0-dev.20181107

Search Terms:
Pick Inconsistent readonly optional

Code

interface T {
    a: string;
    b?: string;
    c: string;
    readonly d: string;
    readonly e?: string;
}
type Test = Pick<T, Exclude<keyof T, 'c'>>;
type Test1 = { [P in Exclude<keyof T, 'c'>]: T[P]; };

Expected behavior:
Test1 should be equal to Test, as it is just an inline version of it

Actual behavior:
Test1 removed any optional or readonly on properties, while Test doesn't.

Playground Link:
Playground

Related Issues:
#14295

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Conditional TypesThe issue relates to conditional typesDomain: Mapped TypesThe issue relates to mapped typesNeeds InvestigationThis issue needs a team member to investigate its status.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions