diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 63b60f534af..3ad6046c85e 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -186,7 +186,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(f: (...args: T[]) => U): (...args: T[]) => U; + freeze(f: (...args: any[]) => T): (...args: any[]) => T; /** * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. diff --git a/tests/baselines/reference/objectFreeze.errors.txt b/tests/baselines/reference/objectFreeze.errors.txt index e820520ed8a..0a1a0518829 100644 --- a/tests/baselines/reference/objectFreeze.errors.txt +++ b/tests/baselines/reference/objectFreeze.errors.txt @@ -1,15 +1,18 @@ -tests/cases/compiler/objectFreeze.ts(5,24): error TS2345: Argument of type '123' is not assignable to parameter of type 'string'. -tests/cases/compiler/objectFreeze.ts(6,2): error TS1128: Declaration or statement expected. +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 (2 errors) ==== - class A { - constructor(public a1: string) { - } - } - function foo(x = new A(123)) { //should error, 123 is not string - ~~~ -!!! error TS2345: Argument of type '123' is not assignable to parameter of type 'string'. - }} - ~ -!!! error TS1128: Declaration or statement expected. \ No newline at end of file + const f = Object.freeze(function foo(a: number, b: string) { return false; }); + f(1, "") === false; + + const a = Object.freeze([1, 2, 3]); + a[0] = 1; + ~~~~ +!!! error TS2542: Index signature in type 'ReadonlyArray' only permits reading. + + const o = Object.freeze({ a: 1, b: "string" }); + o.b = "another"; + ~ +!!! 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 86c2833dabf..51308c8e07c 100644 --- a/tests/baselines/reference/objectFreeze.js +++ b/tests/baselines/reference/objectFreeze.js @@ -1,18 +1,18 @@ //// [objectFreeze.ts] -class A { - constructor(public a1: string) { - } -} -function foo(x = new A(123)) { //should error, 123 is not string -}} +const f = Object.freeze(function foo(a: number, b: string) { return false; }); +f(1, "") === false; + +const a = Object.freeze([1, 2, 3]); +a[0] = 1; + +const o = Object.freeze({ a: 1, b: "string" }); +o.b = "another"; + //// [objectFreeze.js] -var A = (function () { - function A(a1) { - this.a1 = a1; - } - return A; -}()); -function foo(x) { - if (x === void 0) { x = new A(123); } -} +var f = Object.freeze(function foo(a, b) { return false; }); +f(1, "") === false; +var a = Object.freeze([1, 2, 3]); +a[0] = 1; +var o = Object.freeze({ a: 1, b: "string" }); +o.b = "another"; diff --git a/tests/cases/compiler/objectFreeze.ts b/tests/cases/compiler/objectFreeze.ts index e92f9ecd00e..2c93fc8f075 100644 --- a/tests/cases/compiler/objectFreeze.ts +++ b/tests/cases/compiler/objectFreeze.ts @@ -1,6 +1,8 @@ -class A { - constructor(public a1: string) { - } -} -function foo(x = new A(123)) { //should error, 123 is not string -}} \ No newline at end of file +const f = Object.freeze(function foo(a: number, b: string) { return false; }); +f(1, "") === false; + +const a = Object.freeze([1, 2, 3]); +a[0] = 1; + +const o = Object.freeze({ a: 1, b: "string" }); +o.b = "another";