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.
Metadata
Metadata
Assignees
Labels
Unit types including string literal types, numeric literal types, Boolean literals, null, undefinedUnit types including string literal types, numeric literal types, Boolean literals, null, undefinedNot yet reached consensusNot yet reached consensusAn idea for TypeScriptAn idea for TypeScript