Skip to content

Meta: Support Some Form of Static Typing? #4563

Closed
@xixixao

Description

@xixixao

Let's preface this with:

@jashkenas: FWIW [...] I feel very, very strongly about not adding "static" types to CoffeeScript. Period.

Keeping that in mind, a scenario in which I think we could support some type system:

  1. CoffeeScript does not have a type system. Neither static nor dynamic, besides what JS has already.
  2. There should be minimal perf impact.
  3. We should not have to add any more dependencies to the compiler.
  4. If you don't want to use types, we will never force you, and we will not compromise the syntax of CoffeeScript for this support.

What I think we could do is support a syntax that could be used by an existing type system. Afaik there are two popular existing choices in ES6 ecosystem: TypeScript and Flow (add more if you know of any).

No reason to beat around the bush: TypeScript will be much harder to support. It's got more extra syntax to JS.

I imagine that the following code would be possible:

foo = (x: ?number): string ->
  x ? "default string"

Which with Flow would report an error.

I think it might be interesting to figure out the upsides and downsides here and if there is any interest in having this supported. At this point it's very theoretical, as I'm not even sure how much effort it would take to support all of the typing syntax.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions