mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-13 23:48:54 -05:00
Add special handeling for function and array in Object.freeze
This commit is contained in:
12
src/lib/es5.d.ts
vendored
12
src/lib/es5.d.ts
vendored
@@ -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.
|
||||
|
||||
15
tests/baselines/reference/objectFreeze.errors.txt
Normal file
15
tests/baselines/reference/objectFreeze.errors.txt
Normal 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.
|
||||
18
tests/baselines/reference/objectFreeze.js
Normal file
18
tests/baselines/reference/objectFreeze.js
Normal 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); }
|
||||
}
|
||||
6
tests/cases/compiler/objectFreeze.ts
Normal file
6
tests/cases/compiler/objectFreeze.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
constructor(public a1: string) {
|
||||
}
|
||||
}
|
||||
function foo(x = new A(123)) { //should error, 123 is not string
|
||||
}}
|
||||
Reference in New Issue
Block a user