Skip to content

Commit 72df02c

Browse files
committed
Add function
1 parent 8a334ac commit 72df02c

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

src/lib/es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ interface ObjectConstructor {
186186
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
187187
* @param o Object on which to lock the attributes.
188188
*/
189-
freeze<T, U>(f: (...args: T[]) => U): (...args: T[]) => U;
189+
freeze<T>(f: (...args: any[]) => T): (...args: any[]) => T;
190190

191191
/**
192192
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
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.
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.
33

44

55
==== 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.
6+
const f = Object.freeze(function foo(a: number, b: string) { return false; });
7+
f(1, "") === false;
8+
9+
const a = Object.freeze([1, 2, 3]);
10+
a[0] = 1;
11+
~~~~
12+
!!! error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
13+
14+
const o = Object.freeze({ a: 1, b: "string" });
15+
o.b = "another";
16+
~
17+
!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.
18+
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//// [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-
}}
2+
const f = Object.freeze(function foo(a: number, b: string) { return false; });
3+
f(1, "") === false;
4+
5+
const a = Object.freeze([1, 2, 3]);
6+
a[0] = 1;
7+
8+
const o = Object.freeze({ a: 1, b: "string" });
9+
o.b = "another";
10+
811

912
//// [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-
}
13+
var f = Object.freeze(function foo(a, b) { return false; });
14+
f(1, "") === false;
15+
var a = Object.freeze([1, 2, 3]);
16+
a[0] = 1;
17+
var o = Object.freeze({ a: 1, b: "string" });
18+
o.b = "another";

tests/cases/compiler/objectFreeze.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
class A {
2-
constructor(public a1: string) {
3-
}
4-
}
5-
function foo(x = new A(123)) { //should error, 123 is not string
6-
}}
1+
const f = Object.freeze(function foo(a: number, b: string) { return false; });
2+
f(1, "") === false;
3+
4+
const a = Object.freeze([1, 2, 3]);
5+
a[0] = 1;
6+
7+
const o = Object.freeze({ a: 1, b: "string" });
8+
o.b = "another";

0 commit comments

Comments
 (0)