Skip to content

Predefined mapped types in lib.d.ts #12276

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Nov 15, 2016
Merged

Predefined mapped types in lib.d.ts #12276

merged 4 commits into from
Nov 15, 2016

Conversation

ahejlsberg
Copy link
Member

This PR adds the following predefined mapped types to lib.d.ts:

// Make all properties in T optional
type Partial<T> = {
    [P in keyof T]?: T[P];
};

// Make all properties in T readonly
type Readonly<T> = {
    readonly [P in keyof T]: T[P];
};

// From T pick a set of properties K
type Pick<T, K extends keyof T> = {
    [P in K]: T[P];
}

// Construct a type with a set of properties K of type T
type Record<K extends string | number, T> = {
    [P in K]: T;
}

The PR also property implements the identity relation for mapped types.

@ahejlsberg
Copy link
Member Author

@mhegazy Comments?

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants