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 {
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.
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.
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
Original file line number Diff line number Diff line change 22const f = Object . freeze ( function foo ( a : number , b : string ) { return false ; } ) ;
33f ( 1 , "" ) === false ;
44
5+ class C { constructor ( a : number ) { } }
6+ const c = Object . freeze ( C ) ;
7+ new c ( 1 ) ;
8+
59const a = Object . freeze ( [ 1 , 2 , 3 ] ) ;
6- a [ 0 ] = 1 ;
10+ a [ 0 ] = a [ 2 ] . toString ( ) ;
711
812const o = Object . freeze ( { a : 1 , b : "string" } ) ;
9- o . b = "another" ;
13+ o . b = o . a . toString ( ) ;
1014
1115
1216//// [objectFreeze.js]
1317var f = Object . freeze ( function foo ( a , b ) { return false ; } ) ;
1418f ( 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 ) ;
1526var a = Object . freeze ( [ 1 , 2 , 3 ] ) ;
16- a [ 0 ] = 1 ;
27+ a [ 0 ] = a [ 2 ] . toString ( ) ;
1728var 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 11const f = Object . freeze ( function foo ( a : number , b : string ) { return false ; } ) ;
22f ( 1 , "" ) === false ;
33
4+ class C { constructor ( a : number ) { } }
5+ const c = Object . freeze ( C ) ;
6+ new c ( 1 ) ;
7+
48const a = Object . freeze ( [ 1 , 2 , 3 ] ) ;
5- a [ 0 ] = 1 ;
9+ a [ 0 ] = a [ 2 ] . toString ( ) ;
610
711const 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