Closed
Description
Now that we have so many literal types we more than ever need new syntax that would make their use natural. Please consider the following:
const value = (true); // true
const value = true; // boolean
const value = ('a'); // 'a'
const value = 'a'; // string
const value = (1); // 1
const value = 1; // number
const value = ['a', 1]; // (string | number)[]
const value = (['a', 1]) // [string, number]
const value = ([('a'), (1)]) // ['a', 1];
Problem:
- There is no way to get a literal type value without explicit type annotation.
Solution:
- Add new syntax (or shall we say some new semantics to the old mostly unused syntax)
Highlights:
- Composable.
- Works fine with the existing syntax, doesn't need a new one.
- Highly unlikely to be a breaking change.
- Doesn't affect JavaScript semantics at all, can be executed as written and will work as expected.
Shortcomings:
- Undiscoverable syntax.
- Semantic conflicts (breaking changes) although rare:
- generated code
- conditional expressions
- unintended excessive syntax
Prior work:
- Inspired by consider syntax for tuple literals: (['a', 2]) // [string, number] #9217 which is closed in favor of this one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment