File: typeParameterAsTypeParameterConstraint.js

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (44 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//// [typeParameterAsTypeParameterConstraint.ts]
// using a type parameter as a constraint for a type parameter is valid
// no errors expected except illegal constraints

function foo<T, U extends T>(x: T, y: U): U { return y; }

var r = foo(1, 2);
var r = foo({}, 1);

interface A {
    foo: string;
}
interface B extends A {
    bar: number;
}
var a: A;
var b: B;

var r2 = foo(a, b);
var r3 = foo({ x: 1 }, { x: 2, y: 3 });

function foo2<T, U extends { length: T }>(x: T, y: U) { return y; }
foo2(1, '');
foo2({}, { length: 2 }); 
foo2(1, { width: 3, length: 2 }); 
foo2(1, []);
foo2(1, ['']);

//// [typeParameterAsTypeParameterConstraint.js]
// using a type parameter as a constraint for a type parameter is valid
// no errors expected except illegal constraints
function foo(x, y) { return y; }
var r = foo(1, 2);
var r = foo({}, 1);
var a;
var b;
var r2 = foo(a, b);
var r3 = foo({ x: 1 }, { x: 2, y: 3 });
function foo2(x, y) { return y; }
foo2(1, '');
foo2({}, { length: 2 });
foo2(1, { width: 3, length: 2 });
foo2(1, []);
foo2(1, ['']);