microsoft / microsoft/TypeScript

Missing definition from union type when triggered from JSX tag name

Aperta
#43,636 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: JSX/TSX Help Wanted
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

This is a sample code for have a clean issue.

import React from 'react';
class A {
	Renderer = RendererA;
}
class B {
	Renderer = RendererB;
}

const RendererA = () => {
	return <div> A </div>;
};

const RendererB = () => {
	return <div> B </div>;
};

const TestRendererTypes = () => {
	const AB: A | B = null; // just for the demo, AB can be A or B !

	AB.Renderer; //🟩 okey cool,ts find all refs !
	const LostRef = <AB.Renderer />; //🟥 not cool ,ts seem remove refs !
	return LostRef;
};

playground


🙁 Actual behavior

Ts decode only one reference to a function jsx when using inside tag </>
It should show both Renderer ref here !
image

🙂 Expected behavior

We should get all refs like that's . (working if use only a variable ref without a jsx tag <></> )
image


The example is basic, but inside my project i losing all refs, and this is a issu if i need fast track where a rendering is pointing !
And also will give incorrect props Intelisence !
Example here is missing all my others plugins !
image
But if i add a direct ref like that's , i can get all refs, but is polluting my code
image

It seem that's TS have some difficulty to understand JSX !
Is there a hacky and (clean way) to fix this ? or tell me if you guys have temp solutions ?
I hope i exposed correctly my issue !

thanks @+


TSC: Version 4.2.3
Version : 1.55.0 (user setup)
Commit : c185983a683d14c396952dd432459097bc7f757f
Date : 2021-03-30T16:01:55.261Z
Electron : 11.3.0
Chrome : 87.0.4280.141
Node.js : 12.18.3
V8 : 8.7.220.31-electron.0
OS : Windows_NT x64 10.0.19042


Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione TSX fornita e il TypeScript Playground collegato, confrontando la risoluzione dei riferimenti per AB.Renderer con <AB.Renderer />. Traccia il percorso di risoluzione del nome del tag JSX; completato quando vengono riportati entrambi i riferimenti a RendererA e RendererB per l’unione e JSX props/intellisense includono entrambi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.