TS7026 when using JSX factory from a variable rather than import
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- javascript, typescript
- Domaine
- compilers
Piste de recherche
Commencez par la reproduction CodeSandbox liée et comparez la vérification JSX lorsque h est extrait par déstructuration de getPreact() avec l’importation directe. Suivez la manière dont TypeScript identifie la JSX factory et résout JSX.IntrinsicElements ; le travail est terminé lorsque la factory basée sur une variable accepte le JSX sans TS7026, tout en préservant le comportement existant de l’importation directe.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Bug Report
🔎 Search Terms
TS7026: JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
🕗 Version & Regression Information
- This is the behaviour in every version I tried, and I reviewed the FAQ for entries about JSX and React
⏯ Playground Link
https://codesandbox.io/s/dank-wood-cqpld?file=/src/index.tsx
💻 Code
// helping typescript to figure out the types by defining
// the return type as ...
function getPreact(): typeof import("preact") {
// imagine that this function doesn't call require()
// but rather uses some dynamic import, which returns
// the same export that this call would do:
return require("preact");
}
const { h, render } = getPreact();
function App() {
return <div>Hello, world!</div>;
}
render(<App />, document.getElementById("app")!);
🙁 Actual behaviour
TypeScript ignores the h in the scope and errors out any vanilla JSX code because ‘no JSX.IntrinsicElements exist’. Yet it works flawlessly if you compile it ignoring types using, say, Babel. It seems that it also works correctly if you use raw h call instead of JSX.
🙂 Expected behaviour
TypeScript would be smart to figure out that h in scope is a factory method that it needs, as set by configuration (even though it's ‘imported’ weirdly) and use provided by it JSX to find IntrinsicElements and be happy with it.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/TypeScript
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
microsoft/TypeScript#64322 · 2 commentaires · 1 réaction · 2 personnes assignées ·
-
Possible Improvement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
microsoft/TypeScript#64278 · 1 commentaire · 1 réaction ·
-
Docs
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
microsoft/TypeScript#64118 · 1 commentaire ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
microsoft/TypeScript#63959 · 5 commentaires ·
Toutes les issues de microsoft/TypeScript
Issues similaires
-
kind/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
kubernetes-sigs/prow#953 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
caddyserver/caddy#8046 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
-
L1 recommended for recruits
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
optimization optimization:agents-md-curator
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
githubnext/gh-aw-cao#13143 ·