Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ interface ObjectConstructor {
*/
seal<T>(o: T): T;

/**
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
* @param o Object on which to lock the attributes.
*/
freeze<T>(a: T[]): ReadonlyArray<T>;

/**
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
* @param o Object on which to lock the attributes.
*/
freeze<T extends Function>(f: T): T;

/**
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.
* @param o Object on which to lock the attributes.
Expand Down
22 changes: 22 additions & 0 deletions tests/baselines/reference/objectFreeze.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tests/cases/compiler/objectFreeze.ts(9,1): error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
tests/cases/compiler/objectFreeze.ts(12,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.


==== tests/cases/compiler/objectFreeze.ts (2 errors) ====
const f = Object.freeze(function foo(a: number, b: string) { return false; });
f(1, "") === false;

class C { constructor(a: number) { } }
const c = Object.freeze(C);
new c(1);

const a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();
~~~~
!!! error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.

const o = Object.freeze({ a: 1, b: "string" });
o.b = o.a.toString();
~
!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.

29 changes: 29 additions & 0 deletions tests/baselines/reference/objectFreeze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [objectFreeze.ts]
const f = Object.freeze(function foo(a: number, b: string) { return false; });
f(1, "") === false;

class C { constructor(a: number) { } }
const c = Object.freeze(C);
new c(1);

const a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();

const o = Object.freeze({ a: 1, b: "string" });
o.b = o.a.toString();


//// [objectFreeze.js]
var f = Object.freeze(function foo(a, b) { return false; });
f(1, "") === false;
var C = (function () {
function C(a) {
}
return C;
}());
var c = Object.freeze(C);
new c(1);
var a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();
var o = Object.freeze({ a: 1, b: "string" });
o.b = o.a.toString();
12 changes: 12 additions & 0 deletions tests/cases/compiler/objectFreeze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const f = Object.freeze(function foo(a: number, b: string) { return false; });
f(1, "") === false;

class C { constructor(a: number) { } }
const c = Object.freeze(C);
new c(1);

const a = Object.freeze([1, 2, 3]);
a[0] = a[2].toString();

const o = Object.freeze({ a: 1, b: "string" });
o.b = o.a.toString();