Open gfx opened 11 years ago
I prefer the style that places constant literals not to the positions of types, but to the potisions of arguments, like
// NodeJS stuff
class Stream {
function on("data", cb : (Buffer) -> void) : void;
function on("error", cb : (Error) -> void) : void;
function on(event : string, cb : (variant) -> void) : void;
}
// Web stuff
class HTMLElement {
function createElement("div") HTMLDivElement;
function createElement("canvas") HTMLCanvasElement;
function createElement(name : string) : HTMLElement;
}
I prefer TypeScript's because its syntax requires the name of arguments which are overloaded.
+1 to @wasabiz.
I prefer TypeScript's because its syntax requires the name of arguments which are overloaded.
@gfx in such case, do you mean that the compiler should raise a compile error when the names differ? I am against the idea, since in JSX the function arguments are determined by their position, not by name.
@gfx in such case, do you mean that the compiler should raise a compile error when the names differ?
Once JSX supports named parameters, where createElement(name: "div")
will be compiled into createElement("div")
, argument names are required for for the argument and the compiler should raise an error if the names differ.
Considering for a while, I have agreed with @wasabiz and @kazuho because the name is redundant.
http://blogs.msdn.com/b/typescript/archive/2013/03/25/working-on-typescript-0-9-generics-overload-on-constants-and-compiler-performance.aspx
This is a good idea for typed AltJS in order to give types to those methods which type changes by the value of their arguments.
Something like this: