microsoft / microsoft/TypeScript

Better support for global registration patterns

Open
#30,658 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Proposal Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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
)
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the compiler logic used for globalThis and the proposed lib.d.ts JSX.CustomElementsNamespace, then compare them with loading-spinner.ts and loading-spinner.d.ts. The work is done when customElements.define('loading-spinner', LoadingSpinner) can provide JSX typing without the manual namespace declaration.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.