Skip to content

Commit 6039556

Browse files
committed
Handel call and construct signatures
1 parent 72df02c commit 6039556

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/lib/es5.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ interface ObjectConstructor {
182182
*/
183183
freeze<T>(a: T[]): ReadonlyArray<T>;
184184

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 extends (...args: any[]) => any>(f: T): T;
190+
191+
/**
192+
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
193+
* @param o Object on which to lock the attributes.
194+
*/
195+
freeze<T extends new (...args: any[]) => any>(c: T): T;
196+
185197
/**
186198
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
187199
* @param o Object on which to lock the attributes.
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
tests/cases/compiler/objectFreeze.ts(5,1): error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
2-
tests/cases/compiler/objectFreeze.ts(8,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.
1+
tests/cases/compiler/objectFreeze.ts(9,1): error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
2+
tests/cases/compiler/objectFreeze.ts(12,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.
33

44

55
==== tests/cases/compiler/objectFreeze.ts (2 errors) ====
66
const f = Object.freeze(function foo(a: number, b: string) { return false; });
77
f(1, "") === false;
88

9+
class C { constructor(a: number) { } }
10+
const c = Object.freeze(C);
11+
new c(1);
12+
913
const a = Object.freeze([1, 2, 3]);
10-
a[0] = 1;
14+
a[0] = a[2].toString();
1115
~~~~
1216
!!! error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
1317

1418
const o = Object.freeze({ a: 1, b: "string" });
15-
o.b = "another";
19+
o.b = o.a.toString();
1620
~
1721
!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.
1822

tests/baselines/reference/objectFreeze.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22
const f = Object.freeze(function foo(a: number, b: string) { return false; });
33
f(1, "") === false;
44

5+
class C { constructor(a: number) { } }
6+
const c = Object.freeze(C);
7+
new c(1);
8+
59
const a = Object.freeze([1, 2, 3]);
6-
a[0] = 1;
10+
a[0] = a[2].toString();
711

812
const o = Object.freeze({ a: 1, b: "string" });
9-
o.b = "another";
13+
o.b = o.a.toString();
1014

1115

1216
//// [objectFreeze.js]
1317
var f = Object.freeze(function foo(a, b) { return false; });
1418
f(1, "") === false;
19+
var C = (function () {
20+
function C(a) {
21+
}
22+
return C;
23+
}());
24+
var c = Object.freeze(C);
25+
new c(1);
1526
var a = Object.freeze([1, 2, 3]);
16-
a[0] = 1;
27+
a[0] = a[2].toString();
1728
var o = Object.freeze({ a: 1, b: "string" });
18-
o.b = "another";
29+
o.b = o.a.toString();

tests/cases/compiler/objectFreeze.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
const f = Object.freeze(function foo(a: number, b: string) { return false; });
22
f(1, "") === false;
33

4+
class C { constructor(a: number) { } }
5+
const c = Object.freeze(C);
6+
new c(1);
7+
48
const a = Object.freeze([1, 2, 3]);
5-
a[0] = 1;
9+
a[0] = a[2].toString();
610

711
const o = Object.freeze({ a: 1, b: "string" });
8-
o.b = "another";
12+
o.b = o.a.toString();

0 commit comments

Comments
 (0)