File tree Expand file tree Collapse file tree 4 files changed +39
-34
lines changed Expand file tree Collapse file tree 4 files changed +39
-34
lines changed Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ interface ObjectConstructor {
186
186
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
187
187
* @param o Object on which to lock the attributes.
188
188
*/
189
- freeze < T , U > ( f : ( ...args : T [ ] ) => U ) : ( ...args : T [ ] ) => U ;
189
+ freeze < T > ( f : ( ...args : any [ ] ) => T ) : ( ...args : any [ ] ) => T ;
190
190
191
191
/**
192
192
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
Original file line number Diff line number Diff line change 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 .
3
3
4
4
5
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.
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
+
Original file line number Diff line number Diff line change 1
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
- } }
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
+
8
11
9
12
//// [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" ;
Original file line number Diff line number Diff line change 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" ;
You can’t perform that action at this time.
0 commit comments