From 60395565e6fb9767aa6a73a0086238793bb7df58 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 23 Nov 2016 09:48:25 -0800 Subject: [PATCH] Handel call and construct signatures --- src/lib/es5.d.ts | 12 ++++++++++++ .../reference/objectFreeze.errors.txt | 12 ++++++++---- tests/baselines/reference/objectFreeze.js | 19 +++++++++++++++---- tests/cases/compiler/objectFreeze.ts | 8 ++++++-- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 3ad6046c85e..097089e371f 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -182,6 +182,18 @@ interface ObjectConstructor { */ freeze(a: T[]): ReadonlyArray; + /** + * 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 any>(f: T): T; + + /** + * 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 any>(c: T): T; + /** * 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. diff --git a/tests/baselines/reference/objectFreeze.errors.txt b/tests/baselines/reference/objectFreeze.errors.txt index 0a1a0518829..9c28c62f534 100644 --- a/tests/baselines/reference/objectFreeze.errors.txt +++ b/tests/baselines/reference/objectFreeze.errors.txt @@ -1,18 +1,22 @@ -tests/cases/compiler/objectFreeze.ts(5,1): error TS2542: Index signature in type 'ReadonlyArray' only permits reading. -tests/cases/compiler/objectFreeze.ts(8,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. +tests/cases/compiler/objectFreeze.ts(9,1): error TS2542: Index signature in type 'ReadonlyArray' only permits reading. +tests/cases/compiler/objectFreeze.ts(12,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. ==== tests/cases/compiler/objectFreeze.ts (2 errors) ==== const f = Object.freeze(function foo(a: number, b: string) { return false; }); f(1, "") === false; + class C { constructor(a: number) { } } + const c = Object.freeze(C); + new c(1); + const a = Object.freeze([1, 2, 3]); - a[0] = 1; + a[0] = a[2].toString(); ~~~~ !!! error TS2542: Index signature in type 'ReadonlyArray' only permits reading. const o = Object.freeze({ a: 1, b: "string" }); - o.b = "another"; + o.b = o.a.toString(); ~ !!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. \ No newline at end of file diff --git a/tests/baselines/reference/objectFreeze.js b/tests/baselines/reference/objectFreeze.js index 51308c8e07c..4c37631bb10 100644 --- a/tests/baselines/reference/objectFreeze.js +++ b/tests/baselines/reference/objectFreeze.js @@ -2,17 +2,28 @@ const f = Object.freeze(function foo(a: number, b: string) { return false; }); f(1, "") === false; +class C { constructor(a: number) { } } +const c = Object.freeze(C); +new c(1); + const a = Object.freeze([1, 2, 3]); -a[0] = 1; +a[0] = a[2].toString(); const o = Object.freeze({ a: 1, b: "string" }); -o.b = "another"; +o.b = o.a.toString(); //// [objectFreeze.js] var f = Object.freeze(function foo(a, b) { return false; }); f(1, "") === false; +var C = (function () { + function C(a) { + } + return C; +}()); +var c = Object.freeze(C); +new c(1); var a = Object.freeze([1, 2, 3]); -a[0] = 1; +a[0] = a[2].toString(); var o = Object.freeze({ a: 1, b: "string" }); -o.b = "another"; +o.b = o.a.toString(); diff --git a/tests/cases/compiler/objectFreeze.ts b/tests/cases/compiler/objectFreeze.ts index 2c93fc8f075..5e8539831b1 100644 --- a/tests/cases/compiler/objectFreeze.ts +++ b/tests/cases/compiler/objectFreeze.ts @@ -1,8 +1,12 @@ const f = Object.freeze(function foo(a: number, b: string) { return false; }); f(1, "") === false; +class C { constructor(a: number) { } } +const c = Object.freeze(C); +new c(1); + const a = Object.freeze([1, 2, 3]); -a[0] = 1; +a[0] = a[2].toString(); const o = Object.freeze({ a: 1, b: "string" }); -o.b = "another"; +o.b = o.a.toString();