Skip to content

Commit 8a334ac

Browse files
committed
Add special handeling for function and array in Object.freeze
1 parent 2d16b19 commit 8a334ac

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

src/lib/es5.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ interface ObjectConstructor {
176176
*/
177177
seal<T>(o: T): T;
178178

179+
/**
180+
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
181+
* @param o Object on which to lock the attributes.
182+
*/
183+
freeze<T>(a: T[]): ReadonlyArray<T>;
184+
185+
/**
186+
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
187+
* @param o Object on which to lock the attributes.
188+
*/
189+
freeze<T, U>(f: (...args: T[]) => U): (...args: T[]) => U;
190+
179191
/**
180192
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
181193
* @param o Object on which to lock the attributes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/compiler/objectFreeze.ts(5,24): error TS2345: Argument of type '123' is not assignable to parameter of type 'string'.
2+
tests/cases/compiler/objectFreeze.ts(6,2): error TS1128: Declaration or statement expected.
3+
4+
5+
==== tests/cases/compiler/objectFreeze.ts (2 errors) ====
6+
class A {
7+
constructor(public a1: string) {
8+
}
9+
}
10+
function foo(x = new A(123)) { //should error, 123 is not string
11+
~~~
12+
!!! error TS2345: Argument of type '123' is not assignable to parameter of type 'string'.
13+
}}
14+
~
15+
!!! error TS1128: Declaration or statement expected.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [objectFreeze.ts]
2+
class A {
3+
constructor(public a1: string) {
4+
}
5+
}
6+
function foo(x = new A(123)) { //should error, 123 is not string
7+
}}
8+
9+
//// [objectFreeze.js]
10+
var A = (function () {
11+
function A(a1) {
12+
this.a1 = a1;
13+
}
14+
return A;
15+
}());
16+
function foo(x) {
17+
if (x === void 0) { x = new A(123); }
18+
}

tests/cases/compiler/objectFreeze.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class A {
2+
constructor(public a1: string) {
3+
}
4+
}
5+
function foo(x = new A(123)) { //should error, 123 is not string
6+
}}

0 commit comments

Comments
 (0)