Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define literal type during object declaration #14194

Closed
kube opened this issue Feb 20, 2017 · 2 comments
Closed

Define literal type during object declaration #14194

kube opened this issue Feb 20, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@kube
Copy link

kube commented Feb 20, 2017

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 decrement

Current 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.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Feb 8, 2018

Duplicate of #17363 and #20271 and others. please see #20271 (comment) and #10676 for more context.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs Investigation This issue needs a team member to investigate its status. labels Feb 8, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants