Replies: 1 comment
-
What do you think it should look like if the function takes a type parameter and passes that type parameter to another type? Some ideas: function f<T>: Type<T> x, y
function f<T> as Type<T> x, y
function f<T> :: Type<T> x, y |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Function Declaration without Parens
I'd like to be able to write this:
I think it nicely parallels
add x, y
being equivalent toadd(x,y)
.Where this needs discussion is how to properly add types. The arguments are easy:
But where should the return type go? Some options:
(x: number, y: number) => number
.->
as we already do in TypeScript arrow types.this
gets typed in TypeScriptlet return: number
(but that triggers a different meaning forreturn
).return
vs.return.value
#744 (comment)Alternatively, we could allow skipping parentheses when not specifying types, but require parentheses when specifying types.
Typing Function in Function Declaration
A related issue is wanting to type an entire function with an already defined type
T
, instead of typing individual arguments and the return value. Currently you have to switch toconst f: T = ...
instead of usingfunction
. This was mentioned as an annoyance in the Gripescript section of https://shoptalkshow.com/553/.Notation
The obvious notation would be
Unfortunately this already has a meaning in Civet, which is
function f(): T
, e.g.,function f: void
. And it's even worse if we have e.g.function f(x, y): T
.Some alternatives:
Output
Another issue is what to actually compile this to. Ideally we'd preserve the hoisting nature of
function
.var f: T = function f ...
and actually hoist the declaration to the top of the function.T
is a union type; I think it wouldn't behave as well as the first option.Beta Was this translation helpful? Give feedback.
All reactions