|
|
|
|
|
by nkohari
3287 days ago
|
|
Well, in TypeScript you attach the type declaration to the variable declaration: let foo: number;
It's true that you could add the type declaration to the first assignment of the variable, as in: foo: number = 42
...but that's kind of awkward, because CoffeeScript only has an assignment expression and not a variable declaration statement. You can hack the two together but it's going to make things confusing and complex for the compiler to implement. What happens if you do this: foo = 42
... 30 lines later ...
foo: string = "hello"
They're both just assignment expressions, but now they can carry extra metadata about the variable that's being assigned, so there's all sorts of cases you have to consider.Anyways, I was just trying to clarify what the comment you replied to meant. IMO, the real problem is that TypeScript's type system is incredibly powerful, and a huge portion of the compiler is devoted to static checking for it. Even if the CoffeeScript compiler could support types, it makes very little sense to spend the effort when TypeScript already exists. The syntactic difference between the two languages is too small. I could see an option for CoffeeScript to target TypeScript as a transpilation output, but then you'd lose the tooling (tslint) built for TypeScript. And again, why? If you want types, write TypeScript. That's what it's there for. |
|