From d32196ff3640f487c69fffc9e4e8f04e93524cb4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 15 Nov 2016 12:14:46 -0800 Subject: [PATCH] Add predefined mapped types and revise Object.freeze --- src/lib/es5.d.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 2c457a432c6..e402a96fade 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -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(o: T): T; + freeze(o: T): Readonly; /** * Prevents the addition of new properties to an object. @@ -1343,6 +1343,34 @@ interface ArrayLike { readonly [n: number]: T; } +/** + * Make all properties in T optional + */ +type Partial = { + [P in keyof T]?: T[P]; +}; + +/** + * Make all properties in T readonly + */ +type Readonly = { + readonly [P in keyof T]: T[P]; +}; + +/** + * From T pick a set of properties K + */ +type Pick = { + [P in K]: T[P]; +} + +/** + * Construct a type with a set of properties K of type T + */ +type Record = { + [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,