mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 23:12:19 +00:00
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).
26 lines
478 B
TypeScript
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);
|