- Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathcall-inferred.ts
46 lines (36 loc) · 838 Bytes
/
call-inferred.ts
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
45
46
functionfoo<T>(a: T): T{
returna;
}
assert(foo(42)==42);
assert(foo(42.0)==42);
assert(foo(<f32>42.0)==42);
functionbar<T>(a: T=<f32>42.0): T{
returna;
}
assert(bar()==42);
classFoo<T>{
constructor(publicvalue: T){}
staticcreate<T>(value: T): Foo<T>{
returnnewFoo(value);
}
}
assert(newFoo(42).value==42);
assert(Foo.create(42).value==42);
classBar{
doSomething<T>(a: T): T{
returna;
}
}
assert(newBar().doSomething(42)==42);
classBaz<T>extendsFoo<T>{}
assert(newBaz(42).value==42);
// TODO: this'd require return type inference, i.e., omitted return type
// function baz<T>(a: i32): T {
// return a;
// }
// baz(42);
// TODO: this'd ideally be inferred by matching contextualType, avoiding conversions
// function baz<T>(): T {
// return 1;
// }
// baz(42);