New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assigning a type to a string that you are using as a react constructor #99
Comments
Hmm, this should work out of the box. Which version of TS and the react types are you on? |
typescript: 3.2.2 I can't check right now if an update will fix my problems, but will try that later today/tomorrow. |
I am now on: typescript: 3.3.4000 I'm still getting this error.
If I remove the className prop, I simply get:
|
With this entire codebase I get no errors with the same version: import React from 'react'
type Props = {
tag: 'h1' | 'h2' | 'h3'
}
export const Component = (props: Props) => {
const text = 'abc'
const HeaderTag = props.tag
return <HeaderTag>{text}</HeaderTag>
} Is there anything else you're leaving out? maybe a minimally-reproducible repo would help too. |
Okay, that's good to hear! I'll see if I can make a small repo that has the issue. |
I cannot replicate it outside my project. Must be something about my current project that is causing this. Thanks for looking. |
ha, good to know. ifyou ever do figure out what blocked it, i'm super curious to hear! |
Hard to figure out how to write this, so I'll just give an example:
Example:
Error:
It doesn't like me giving any children to
<HeaderTag>
even though I know<h1>
etc. can obviously have string children.I tried typing the
HeaderTag
variable but I didn't know what to type it as, because Typescript knowsheaderTag
is just a string.The solution I came up with isn't really what I want to do, since it uses
React.createElement
:return React.createElement(props.headerTag, {}, text)
How should I be doing?
The text was updated successfully, but these errors were encountered: