microsoft / microsoft/TypeScript
Better support for global registration patterns
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Suggestion
It seems likely the compiler logic used for globalThis could be reused to support automated global types for custom elements , which is especially annoying and difficult to deal with in jsx
Use Cases
this is the current dev workflow for creating and using custom elements
The custom element
loading-spinner.ts
class LoadingSpinner extends HTMLElement {
constructor() {
super();
this.innerHTML = `<div class="loading-spinnner">`
}
//omitting code for brevity
}
customElements.define('loading-spinner', LoadingSpinner); //<-- could this be added to a global namespace using similar logic as globalThis ?
the type definition
loading-spinner.d.ts
//this is coupled to a specific JSX namespace's types (preact in this case)
//maybe adding a JSX.CustomElementsNamespace to lib.d.ts could be an option as well?
interface LoadingSpinner extends JSX.HTMLAttributes {}
declare namespace JSX {
interface IntrinsicElements {
'loading-spinner': LoadingSpinner;
}
}
Using the custom component
usage in a jsx component
import h from Reactish
let MyComponent = () => {
return (
<loading-spinner/> //<--so difficult not to get errors here
)
}
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der für globalThis verwendeten Compilerlogik und dem vorgeschlagenen lib.d.ts JSX.CustomElementsNamespace und vergleiche sie anschließend mit loading-spinner.ts und loading-spinner.d.ts. Die Arbeit ist abgeschlossen, wenn customElements.define('loading-spinner', LoadingSpinner) JSX-Typisierung ohne die manuelle Namespace-Deklaration bereitstellen kann.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers, frontend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100