4 ms·
A benefit of ident: Type is that it allows you to express complex anonymous types. Example from Typescript: const foo: 'A' | 'B' | 'C' = 'A' Which states tha
by marmada 6y ago
A benefit of ident: Type is that it allows you to express complex anonymous types.
Example from Typescript:
const foo: 'A' | 'B' | 'C' = 'A'
Which states that foo must belong to the given union type. How would this look in a Type ident language?
const 'A' | 'B' | 'C' foo
That doesn't seem right. There's no clear barrier between the type and the identifier name.
Here's another contrived example:
const foo: () => Promise<void> = async (x) => console.log(x)
Here foo is of type "() => Promise<void>". How would this look in a Type ident language?
const () => Promise<void> foo = async (x) => console.log(x)
To me, this is unclear because it is hard to tell where the type ends and the actual function begins.
Last example.
const foo: { [string]: number} = {"hello": 3}
I believe says that foo is an object with string keys and number values.
What does this look like in a Type ident language?
const { [string]: number} foo = {"hello": 3}
I think all of the Type ident examples are more confusing because it's to tell where the type ends and the name begins (this is most clear in the first example). This probably makes syntax highlighting worse/parsing more complicated/is tougher on the user. With ident: Type, it is very clear that the type starts after the ":" and ends before the "=" sign.