Add special handeling for function and array in Object.freeze

This commit is contained in:
Mohamed Hegazy
2016-11-21 23:13:22 -08:00
parent 2d16b19ef9
commit 8a334ac00d
4 changed files with 51 additions and 0 deletions

12
src/lib/es5.d.ts vendored
View File

@@ -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, U>(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.

View File

@@ -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.

View File

@@ -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); }
}

View File

@@ -0,0 +1,6 @@
class A {
constructor(public a1: string) {
}
}
function foo(x = new A(123)) { //should error, 123 is not string
}}