1
0
mirror of https://github.com/fluencelabs/assemblyscript synced 2025-05-04 03:12:16 +00:00
dcodeIO ee73a4d28f Initial type parameter inference, see
This catches the most common cases but doesn't yet implement inference involving the return type because some prequesites are not yet in place (see test case).
2018-04-13 12:25:27 +02:00

26 lines
478 B
TypeScript

function foo<T>(a: T): T {
return a;
}
assert(foo(42) == 42);
assert(foo(42.0) == 42);
assert(foo(<f32>42.0) == 42);
function bar<T>(a: T = <f32>42.0): T {
return a;
}
assert(bar() == 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);