-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Problem
During object declaration, there is no way to explicitly define a property literal type:
const obj = {
hello: 'world'
}Here typeof obj is { hello: string }
Example of Use Case
In the case of a Redux Action, which will be constant, I expect type property to be a literal type:
const increment = {
type: 'INCREMENT'
}
const decrement = {
type: 'DECREMENT'
}
export type Action =
& typeof increment
& typeof decrementCurrent Workaround
It's possible to explicitly define the literal type after the value:
const increment = {
type: 'INCREMENT' as 'INCREMENT'
}Which causes two problems:
- redundancy
- misspelling won't be analysed (
'foo' as 'bar'will work)
readonly would be a solution, but does not seem to be compatible with object declaration syntax.
maxlk and jeremistadler
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created