microsoft / microsoft/TypeScript
Enum is not assignable to type string
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il repro collegato di TypeScript Playground e confronta il suo comportamento tra le versioni 4.1.15 e 4.2.2. Segui il percorso di type-checking per il valore dell’enum passato all’attributo stringa JSX, quindi aggiungi un test di regressione; il lavoro è completato quando il repro non segnala più TS2322.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100