question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing definition from union type when triggered from JSX tag name

See original GitHub issue

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


Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
andrewbranchcommented, Apr 12, 2021
image

Doesn’t repro for me. Can you share a project/repo?

1reaction
djmisterjoncommented, Apr 12, 2021

Oh, you’re talking about definitions, not references. That repros.

ho yes, i’m sorry for the confusion, i’m not always comfortable with english terminology. thanks for the information !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Omitting a shared property from a union type of objects results ...
Omitting a shared property from a union type of objects results in error when using non-shared properties (TypeScript) - Stack Overflow. Stack ...
Read more >
Advanced typescript for React developers - discriminated unions
Exploring how to discriminate unions properly and how this pattern can be useful for React developers' everyday professional life.
Read more >
Union types in TypeScript: modeling state - matiasklemola.com
Data is a tagged union, also known as a discriminated union. We need some kind of way to tell different options apart -...
Read more >
Fullstack part9 | React with types
Element => { // We are explicitly defining the return type of a function here // (i.e., a react component). return <div>TypeScript React...
Read more >
Handbook - Unions and Intersection Types - TypeScript
That means that we can call it with an argument that's neither a number nor a string , but TypeScript will be okay...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found