by ravenstine · 4y ago · 0 comments
---
const user: User = {
...
};---
Why couldn't this be more like C rather than this weird conflation with the existing colon token?
---
const User user = {
...
};---
That might seem not as pleasing to those familiar with Typescript, but it's much closer to other existing syntaxes (meaning less of a learning curve coming from Java or C).
Same with function definitions:
---
function foo (bar: string, baz: boolean): Qux {
...
}---
Versus:
---
Qux function foo (string bar, bool baz) {
...
}---
I find the latter much more familiar than Typescript and less confusing. It's also slightly less verbose.
void function () { return 42; }(); // returns undefined
It's not something you would usually use in your code, but many Javascript minimizers make heavy use of it, and Typescript must know how to handle any valid Javascript without ambiguity.[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
The name is usually more important than the type so I like that typescript puts it first.
The current syntax seems better for type inference and gradual typing.
[0] https://learnxinyminutes.com/docs/ocaml/
[1] https://learnxinyminutes.com/docs/rust/
[2] https://learnxinyminutes.com/docs/kotlin/
[3] https://learnxinyminutes.com/docs/haxe/
[4] https://learnxinyminutes.com/docs/nim/
[5] https://learnxinyminutes.com/docs/swift/
[6] https://learnxinyminutes.com/docs/elm/
let user = new User();
let user: User = new User();