Dynamic TagName causing error after version upgrade
See original GitHub issuetypescript version: 3.2.2 IDE: VS Code
Description: I updated from v3.1.6 to v3.2.2. This is my code:
import * as React from 'react';
export interface Props {
tag?: string,
};
const MyComponent: React.FunctionComponent<Props> = ({
tag: Tag = 'div', children
}) => {
return (
<Tag> // this is causing the error
{children}
</Tag>
);
};
Expected: No error
Actual:
Error produced:
[ts] Type '{ children: ReactNode; }' has no properties in common with type 'IntrinsicAttributes'. [2559]
This seems like a regression as it worked in v3.1.6
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:16 (1 by maintainers)
Top Results From Across the Web
When are dynamic tags applied? - Qualys Discussions
We wanted to create a dynamic tag for the presence of a specific QID. This seems like a pretty straightforward process. Create New...
Read more >Cannot change version of project facet Dynamic Web Module ...
Change the dynamic web module version in this line to 3.0 - <installed ... Right Click on The Project Folder > Maven >...
Read more >AdWords Conversion Tracking Errors - Tag Assistant Help
This means that Conversion Tracking code is not implemented properly on the page and no conversions will be tracked. Solution: Move the Conversion...
Read more >What's Wrong With The Docker :latest Tag? - vsupalov.com
Docker images tagged with :latest have caused many people a lot of trouble. ... Tell immediately what code version is running based on...
Read more >Dynamic policies - FortiClient EMS
EMS dynamically updates these endpoint groups when host compliance or other events occur, causing FortiOS to dynamically adjust its security policies based on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone reading this: This error is pretty much correct and is because making a tag out of an arbitrary string isn’t really typesafe. The
NeedsInvestigation
tag is, IIRC, just to find why it worked before we refactored how we handled JSX (it shouldn’t have from what I know…). In your code, if you want to say that you have a valid html tag name, you should usekeyof React.ReactDOM
instead ofstring
(which, FYI contains both the HTML and SVG elements - if you only intend for one or the other, you should select eitherReactSVG
orReactHTML
instead).JSX.IntrinsicElements
contains no definition for the props for something of typestring
(that would require an index signature, whichreact
does not define). This makes perfect sense -react
has no idea how to make a"foobar"
tag correctly. Withinreact
’s types,ReactType
is defined in a similar fashion (in terms ofJSX.IntrinsicElements
).If anything, I’d say that the preferred workaround for anyone who finds this, rather than suppressing the error, is trying to rejigger their
string
type into thekeyof React.ReactDOM
(orkeyof JSX.IntrinsicElements
) union instead.This seems to work:
This is the calculated type of
tag
:…until you try to add a
ref
prop toTag
. Then you get the error: