Add function

This commit is contained in:
Mohamed Hegazy
2016-11-21 23:27:18 -08:00
parent 8a334ac00d
commit 72df02cbbd
4 changed files with 39 additions and 34 deletions

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

@@ -186,7 +186,7 @@ interface ObjectConstructor {
* 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;
freeze<T>(f: (...args: any[]) => T): (...args: any[]) => T;
/**
* Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

View File

@@ -1,15 +1,18 @@
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(5,1): error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
tests/cases/compiler/objectFreeze.ts(8,3): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.
==== 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.
const f = Object.freeze(function foo(a: number, b: string) { return false; });
f(1, "") === false;
const a = Object.freeze([1, 2, 3]);
a[0] = 1;
~~~~
!!! error TS2542: Index signature in type 'ReadonlyArray<number>' only permits reading.
const o = Object.freeze({ a: 1, b: "string" });
o.b = "another";
~
!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property.

View File

@@ -1,18 +1,18 @@
//// [objectFreeze.ts]
class A {
constructor(public a1: string) {
}
}
function foo(x = new A(123)) { //should error, 123 is not string
}}
const f = Object.freeze(function foo(a: number, b: string) { return false; });
f(1, "") === false;
const a = Object.freeze([1, 2, 3]);
a[0] = 1;
const o = Object.freeze({ a: 1, b: "string" });
o.b = "another";
//// [objectFreeze.js]
var A = (function () {
function A(a1) {
this.a1 = a1;
}
return A;
}());
function foo(x) {
if (x === void 0) { x = new A(123); }
}
var f = Object.freeze(function foo(a, b) { return false; });
f(1, "") === false;
var a = Object.freeze([1, 2, 3]);
a[0] = 1;
var o = Object.freeze({ a: 1, b: "string" });
o.b = "another";

View File

@@ -1,6 +1,8 @@
class A {
constructor(public a1: string) {
}
}
function foo(x = new A(123)) { //should error, 123 is not string
}}
const f = Object.freeze(function foo(a: number, b: string) { return false; });
f(1, "") === false;
const a = Object.freeze([1, 2, 3]);
a[0] = 1;
const o = Object.freeze({ a: 1, b: "string" });
o.b = "another";