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