File tree Expand file tree Collapse file tree 4 files changed +41
-10
lines changed Expand file tree Collapse file tree 4 files changed +41
-10
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,18 @@ interface ObjectConstructor {
182
182
*/
183
183
freeze < T > ( a : T [ ] ) : ReadonlyArray < T > ;
184
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 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
+
185
197
/**
186
198
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
187
199
* @param o Object on which to lock the attributes.
Original file line number Diff line number Diff line change 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.
3
3
4
4
5
5
==== tests/cases/compiler/objectFreeze.ts (2 errors) ====
6
6
const f = Object.freeze(function foo(a: number, b: string) { return false; });
7
7
f(1, "") === false;
8
8
9
+ class C { constructor(a: number) { } }
10
+ const c = Object.freeze(C);
11
+ new c(1);
12
+
9
13
const a = Object.freeze([1, 2, 3]);
10
- a[0] = 1 ;
14
+ a[0] = a[2].toString() ;
11
15
~~~~
12
16
!!! error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
13
17
14
18
const o = Object.freeze({ a: 1, b: "string" });
15
- o.b = "another" ;
19
+ o.b = o.a.toString() ;
16
20
~
17
21
!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.
18
22
Original file line number Diff line number Diff line change 2
2
const f = Object . freeze ( function foo ( a : number , b : string ) { return false ; } ) ;
3
3
f ( 1 , "" ) === false ;
4
4
5
+ class C { constructor ( a : number ) { } }
6
+ const c = Object . freeze ( C ) ;
7
+ new c ( 1 ) ;
8
+
5
9
const a = Object . freeze ( [ 1 , 2 , 3 ] ) ;
6
- a [ 0 ] = 1 ;
10
+ a [ 0 ] = a [ 2 ] . toString ( ) ;
7
11
8
12
const o = Object . freeze ( { a : 1 , b : "string" } ) ;
9
- o . b = "another" ;
13
+ o . b = o . a . toString ( ) ;
10
14
11
15
12
16
//// [objectFreeze.js]
13
17
var f = Object . freeze ( function foo ( a , b ) { return false ; } ) ;
14
18
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 ) ;
15
26
var a = Object . freeze ( [ 1 , 2 , 3 ] ) ;
16
- a [ 0 ] = 1 ;
27
+ a [ 0 ] = a [ 2 ] . toString ( ) ;
17
28
var o = Object . freeze ( { a : 1 , b : "string" } ) ;
18
- o . b = "another" ;
29
+ o . b = o . a . toString ( ) ;
Original file line number Diff line number Diff line change 1
1
const f = Object . freeze ( function foo ( a : number , b : string ) { return false ; } ) ;
2
2
f ( 1 , "" ) === false ;
3
3
4
+ class C { constructor ( a : number ) { } }
5
+ const c = Object . freeze ( C ) ;
6
+ new c ( 1 ) ;
7
+
4
8
const a = Object . freeze ( [ 1 , 2 , 3 ] ) ;
5
- a [ 0 ] = 1 ;
9
+ a [ 0 ] = a [ 2 ] . toString ( ) ;
6
10
7
11
const o = Object . freeze ( { a : 1 , b : "string" } ) ;
8
- o . b = "another" ;
12
+ o . b = o . a . toString ( ) ;
You can’t perform that action at this time.
0 commit comments