Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Predefined mapped types in lib.d.ts#12276

Merged
ahejlsberg merged 4 commits into
mastermicrosoft/TypeScript:masterfrom
libMappedTypesmicrosoft/TypeScript:libMappedTypesCopy head branch name to clipboard
Nov 15, 2016
Merged

Predefined mapped types in lib.d.ts#12276
ahejlsberg merged 4 commits into
mastermicrosoft/TypeScript:masterfrom
libMappedTypesmicrosoft/TypeScript:libMappedTypesCopy head branch name to clipboard

Conversation

@ahejlsberg

Copy link
Copy Markdown
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
Copy Markdown
Member Author

@mhegazy Comments?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.