From b29077a19baee97a8d86e2c7851953569652918e Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 13 Apr 2015 12:57:50 -0700 Subject: [PATCH] Add destructuring parameter with generic --- ...tructuringParameterDeclaration4.errors.txt | 27 +++++++++ .../destructuringParameterDeclaration4.js | 58 +++++++++++++++++++ .../destructuringParameterDeclaration4.ts | 18 ++++++ 3 files changed, 103 insertions(+) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration4.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration4.js create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt new file mode 100644 index 00000000000..cf4b15d1271 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (1 errors) ==== + interface F { } + class C implements F{ + } + function foo(...a: T[]) { } + function foo1(...a: T[]) { } + function bar({x} = { x: new C() }) { } + function baz({x}: { x: F }) { } + function baz1({x}: { x: C }) { } + function baz2({x}: { x: C }) { } + + var obj = new C(); + baz1({ x: obj }); + baz({ x: new C() }); + baz({ x: {} }); + foo("hello", 1, 2); + ~~~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. + foo("hello", 1, 2); + foo("hello", "world"); + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.js b/tests/baselines/reference/destructuringParameterDeclaration4.js new file mode 100644 index 00000000000..3f83402dffa --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration4.js @@ -0,0 +1,58 @@ +//// [destructuringParameterDeclaration4.ts] +interface F { } +class C implements F{ +} +function foo(...a: T[]) { } +function foo1(...a: T[]) { } +function bar({x} = { x: new C() }) { } +function baz({x}: { x: F }) { } +function baz1({x}: { x: C }) { } +function baz2({x}: { x: C }) { } + +var obj = new C(); +baz1({ x: obj }); +baz({ x: new C() }); +baz({ x: {} }); +foo("hello", 1, 2); +foo("hello", 1, 2); +foo("hello", "world"); + + + +//// [destructuringParameterDeclaration4.js] +var C = (function () { + function C() { + } + return C; +})(); +function foo() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function foo1() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function bar(_a) { + var x = (_a === void 0 ? { x: new C() } : _a).x; +} +function baz(_a) { + var x = _a.x; +} +function baz1(_a) { + var x = _a.x; +} +function baz2(_a) { + var x = _a.x; +} +var obj = new C(); +baz1({ x: obj }); +baz({ x: new C() }); +baz({ x: {} }); +foo("hello", 1, 2); +foo("hello", 1, 2); +foo("hello", "world"); diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts new file mode 100644 index 00000000000..b59c539d672 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts @@ -0,0 +1,18 @@ +interface F { } +class C implements F{ +} +function foo(...a: T[]) { } +function foo1(...a: T[]) { } +function bar({x} = { x: new C() }) { } +function baz({x}: { x: F }) { } +function baz1({x}: { x: C }) { } +function baz2({x}: { x: C }) { } + +var obj = new C(); +baz1({ x: obj }); +baz({ x: new C() }); +baz({ x: {} }); +foo("hello", 1, 2); +foo("hello", 1, 2); +foo("hello", "world"); +