microsoft / microsoft/TypeScript
Define 'tagName' values in Element interfaces to prevent misleading type acceptance.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
- HTML Element Interfaces
- Element tagName
- Element Interfaces
- Incorrect element types accepted
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Element interfaces
⏯ Playground Link
Playground link with relevant code
💻 Code
// Elements can be assigned to variables of other element types because of interface overlaps being sufficient.
let element: HTMLSpanElement = document.createElement("div");
// If the interfaces included the appropriate 'tagName' property this could be avoided...
let spanElement: HTMLSpanElement & { tagName: "SPAN" } = document.createElement("div") as HTMLDivElement & { tagName: "DIV" };
🙁 Actual behavior
e.g. 'HTMLDivElement' instance can be assigned to variables of type 'HTMLSpanElement'.
🙂 Expected behavior
This should fail the type checking to avoid accidentally assigning elements of an incorrect type.
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 dalla riproduzione collegata di TypeScript Playground ed esamina le interfacce HTML Element coinvolte, in particolare tagName su HTMLSpanElement e HTMLDivElement. Il lavoro è completato quando un HTMLDivElement non viene più accettato come HTMLSpanElement, mentre il comportamento mostrato dell’intersezione di tagName continua a essere rappresentato accuratamente.
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
- 38/100