TS7026 when using JSX factory from a variable rather than import
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
Direzione di ricerca
Inizia con la riproduzione collegata su CodeSandbox e confronta il controllo JSX quando h viene destrutturato da getPreact() con l’importazione diretta. Traccia il modo in cui TypeScript identifica la JSX factory e risolve JSX.IntrinsicElements; il lavoro è completato quando la factory basata su variabile accetta il JSX senza TS7026, preservando il comportamento esistente dell’importazione diretta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
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.
Altre issue di microsoft/TypeScript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
microsoft/TypeScript#64322 · 2 commenti · 1 reazione · 2 assegnatari ·
-
Possible Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/TypeScript#64278 · 1 commento · 1 reazione ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
microsoft/TypeScript#64118 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TypeScript#63959 · 5 commenti ·
Tutte le issue di microsoft/TypeScript
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
kubernetes-sigs/prow#953 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
caddyserver/caddy#8046 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
jaegertracing/jaeger#9588 ·