microsoft / microsoft/TypeScript
Enum is not assignable to type string
Open
Nobody has claimed this yet.
In Discussion
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
Strings in an Enum form are not assignable to fields that require type string.
🔎 Search Terms
- Enum as a string parameter
- Enum is not assignable to type string
- TS2322
🕗 Version & Regression Information
- This is the behavior between versions
4.1.15and4.2.2.
⏯ Playground Link
Playground link with relevant code
💻 Code
import React from 'react'
enum Config {
Name = 'TS',
Width = 200,
Height = 200
}
export default function Example(){
return <div id={Config.Name}></div>
}
🙁 Actual behavior
The terminal is complaining with the following message:
Type 'Config' is not assignable to type 'string | undefined'.
🙂 Expected behavior
Code works without the error message.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground repro and compare its behavior between versions 4.1.15 and 4.2.2. Trace the type-checking path for the enum value passed to the JSX string attribute, then add a regression test; done means the repro no longer reports TS2322.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100