mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-17 00:41:32 +00:00
Generic function type aliases
This commit is contained in:
15
tests/compiler/function-types.ts
Normal file
15
tests/compiler/function-types.ts
Normal file
@ -0,0 +1,15 @@
|
||||
type Adder<T> = (a: T, b: T) => T;
|
||||
|
||||
function makeAdder<T>(): Adder<T> {
|
||||
return (a: T, b: T): T => {
|
||||
return a + b;
|
||||
};
|
||||
}
|
||||
|
||||
var i32Adder = makeAdder<i32>();
|
||||
i32Adder(1, 2);
|
||||
|
||||
var i64Adder = makeAdder<i64>();
|
||||
i64Adder(1, 2);
|
||||
|
||||
makeAdder<f64>()(1, 2);
|
Reference in New Issue
Block a user