Add predefined mapped types and revise Object.freeze

This commit is contained in:
Anders Hejlsberg 2016-11-15 12:14:46 -08:00
parent fe3f88cd08
commit d32196ff36

30
src/lib/es5.d.ts vendored
View File

@ -180,7 +180,7 @@ interface ObjectConstructor {
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
* @param o Object on which to lock the attributes.
*/
freeze<T>(o: T): T;
freeze<T>(o: T): Readonly<T>;
/**
* Prevents the addition of new properties to an object.
@ -1343,6 +1343,34 @@ interface ArrayLike<T> {
readonly [n: number]: T;
}
/**
* 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;
}
/**
* Represents a raw buffer of binary data, which is used to store data for the
* different typed arrays. ArrayBuffers cannot be read from or written to directly,