jsx / JSX

JSX - a faster, safer, easier JavaScript
http://jsx.github.io/
MIT License
1.47k stars 102 forks source link

Overload on Constants (from TypeScript) #220

Open gfx opened 11 years ago

gfx commented 11 years ago

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:

// NodeJS stuff
class Stream {
  function on(event : "data", cb : (Buffer) -> void) : void;
  function on(event : "error", cb : (Error) -> void) : void;
  function on(event : string, cb : (variant) -> void) : void;
}

// Web stuff
class HTMLElement {
  function createElement(name : "div") HTMLDivElement;
  function createElement(name : "canvas") HTMLCanvasElement;
  function createElement(name : string) : HTMLElement;
}
nyuichi commented 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;
}
gfx commented 11 years ago

I prefer TypeScript's because its syntax requires the name of arguments which are overloaded.

kazuho commented 11 years ago

+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 commented 11 years ago

@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.

gfx commented 11 years ago

Considering for a while, I have agreed with @wasabiz and @kazuho because the name is redundant.