mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 11:24:49 -05:00
Add destructuring parameter with generic
This commit is contained in:
@@ -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<T>(...a: T[]) { }
|
||||
function foo1<T extends String>(...a: T[]) { }
|
||||
function bar<T extends C>({x} = { x: new C() }) { }
|
||||
function baz<T extends F>({x}: { x: F }) { }
|
||||
function baz1<T extends C>({x}: { x: C }) { }
|
||||
function baz2<T extends C>({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<number|string>("hello", 1, 2);
|
||||
foo("hello", "world");
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//// [destructuringParameterDeclaration4.ts]
|
||||
interface F { }
|
||||
class C implements F{
|
||||
}
|
||||
function foo<T>(...a: T[]) { }
|
||||
function foo1<T extends String>(...a: T[]) { }
|
||||
function bar<T extends C>({x} = { x: new C() }) { }
|
||||
function baz<T extends F>({x}: { x: F }) { }
|
||||
function baz1<T extends C>({x}: { x: C }) { }
|
||||
function baz2<T extends C>({x}: { x: C }) { }
|
||||
|
||||
var obj = new C();
|
||||
baz1({ x: obj });
|
||||
baz({ x: new C() });
|
||||
baz({ x: {} });
|
||||
foo("hello", 1, 2);
|
||||
foo<number|string>("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");
|
||||
@@ -0,0 +1,18 @@
|
||||
interface F { }
|
||||
class C implements F{
|
||||
}
|
||||
function foo<T>(...a: T[]) { }
|
||||
function foo1<T extends String>(...a: T[]) { }
|
||||
function bar<T extends C>({x} = { x: new C() }) { }
|
||||
function baz<T extends F>({x}: { x: F }) { }
|
||||
function baz1<T extends C>({x}: { x: C }) { }
|
||||
function baz2<T extends C>({x}: { x: C }) { }
|
||||
|
||||
var obj = new C();
|
||||
baz1({ x: obj });
|
||||
baz({ x: new C() });
|
||||
baz({ x: {} });
|
||||
foo("hello", 1, 2);
|
||||
foo<number|string>("hello", 1, 2);
|
||||
foo("hello", "world");
|
||||
|
||||
Reference in New Issue
Block a user