-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Broken jsx element with not static type with ts 3.2.1 #28768
Comments
Related: #28631 |
It's because we started strongly checking tag calls such as these, and the |
Please consider this now broken example: import React, {
ReactType,
StatelessComponent,
} from "react"
import classNames from "classnames"
interface Props {
className?: string
}
export function createStyledComponent<P extends { className: string }>(
Component: ReactType<P>,
className: string
): StatelessComponent<Props> {
return props => (
<Component className={classNames(className, props.className)}>
{props.children}
</Component>
)
}
Is this something that should be addressed in @types/react? |
Nothing that can be done on the Note that your |
@Kovensky Oops, the existing (working) code I had was: export function createStyledComponent(
Component: ReactType,
className: string
): StatelessComponent<Props> {
return props => (
<Component className={classNames(className, props.className)}>
{props.children}
</Component>
)
} That generic change was an attempt to get it working under TS 3.2.1 |
TypeScript 3.2 has better support for generic-typed object spreads, which helped in another commit. Compile errors were due to: - microsoft/TypeScript#28768
Just a small reproduction: How I had to fix it: const inp = (
<Input
textArea={abc as boolean}
/>
) even though my union type is type InputProps = {
textArea?: false
// more types where textArea would be undefined or false
} & {
textArea: true
// more types where textArea would be true
} |
@weswigham can we get a fresh read on this? |
The OP's example should have been fixed by #29011 (and testing shows it is). @rhys-vdw's example here also works. @azizhk's example probably typechecks better than he wants, because we correctly reject the spread of a |
Hi, I just upgraded to
I can use this for string components now But I cannot use this for components which have generics class OptionGroupCheckBox<OptionType> extends React.PureComponent<OptionGroupProps<OptionType>> {
// methods
}
class OptionGroupRadio<OptionType> extends React.PureComponent<OptionGroupProps<OptionType>> {
// methods
}
const OptionGroup = condition ? OptionGroupCheckBox : OptionGroupRadio;
const vdom = (
<OptionGroup
// OptionGroupProps<OptionType>
/>
) |
TypeScript Version: 3.2.1
Search Terms:
jsx
Code
Expected behavior:
Everything is ok. TypeScript 3.1.6 compiles it properly.
Actual behavior:
error: JSX element type 'Tag' does not have any construct or call signatures. [2604]
The text was updated successfully, but these errors were encountered: