assemblyscript/tests/compiler/optional-typeparameters.ts
Daniel Wirtz ebae7cbd73
Implement optional type parameters (#360)
* Add a NATIVE<T> macro type to simplify use of a native WebAssembly type
* Add default type parameters for internal helpers for explicit loads and stores
* Unify loadUnsafe/loadUnsafeWithOffset etc. into one
* Renamed loadUnsafe etc. into just LOAD, like a macro
* Implement parsing of index signatures, but ignore them, for properly linting code
* Refactor TypedArray<T> to use macros
2018-12-07 14:33:32 +01:00

29 lines
492 B
TypeScript

function testConcrete<T,U = i32>(a: T): U {
return a;
}
function testDerived<T,U = T>(a: T): U {
return a;
}
testConcrete<i32>(1);
testDerived<i32>(2);
class TestConcrete<T,U = i32> {
test<V = i32>(a: T, b: U): V {
return a + b;
}
}
class TestDerived<T,U = T> {
test<V = U>(a: T, b: U): V {
return a + b;
}
}
import "allocator/arena";
var tConcrete = new TestConcrete<i32>();
tConcrete.test<i32>(1, 2);
var tDerived = new TestDerived<f64>()
tDerived.test<f64>(1, 2);