diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 7ee47817802..63b60f534af 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -176,6 +176,18 @@ interface ObjectConstructor { */ seal(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(a: T[]): ReadonlyArray; + + /** + * 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(f: (...args: T[]) => U): (...args: T[]) => U; + /** * 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. diff --git a/tests/baselines/reference/objectFreeze.errors.txt b/tests/baselines/reference/objectFreeze.errors.txt new file mode 100644 index 00000000000..e820520ed8a --- /dev/null +++ b/tests/baselines/reference/objectFreeze.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/objectFreeze.ts(5,24): error TS2345: Argument of type '123' is not assignable to parameter of type 'string'. +tests/cases/compiler/objectFreeze.ts(6,2): error TS1128: Declaration or statement expected. + + +==== tests/cases/compiler/objectFreeze.ts (2 errors) ==== + class A { + constructor(public a1: string) { + } + } + function foo(x = new A(123)) { //should error, 123 is not string + ~~~ +!!! error TS2345: Argument of type '123' is not assignable to parameter of type 'string'. + }} + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/objectFreeze.js b/tests/baselines/reference/objectFreeze.js new file mode 100644 index 00000000000..86c2833dabf --- /dev/null +++ b/tests/baselines/reference/objectFreeze.js @@ -0,0 +1,18 @@ +//// [objectFreeze.ts] +class A { + constructor(public a1: string) { + } +} +function foo(x = new A(123)) { //should error, 123 is not string +}} + +//// [objectFreeze.js] +var A = (function () { + function A(a1) { + this.a1 = a1; + } + return A; +}()); +function foo(x) { + if (x === void 0) { x = new A(123); } +} diff --git a/tests/cases/compiler/objectFreeze.ts b/tests/cases/compiler/objectFreeze.ts new file mode 100644 index 00000000000..e92f9ecd00e --- /dev/null +++ b/tests/cases/compiler/objectFreeze.ts @@ -0,0 +1,6 @@ +class A { + constructor(public a1: string) { + } +} +function foo(x = new A(123)) { //should error, 123 is not string +}} \ No newline at end of file