-
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
JSX element type does not have any construct or call signatures in v3.2.0-rc #28631
Comments
This is missing the rest of the error message but, to be sure, make sure you are on the latest version of EDIT: you probably mean to use ComponentType and not ReactType |
@Kovensky I have make sure using the latest I revert back to |
Typescript 3.2.1 other example interface P1 {
p?: boolean
c?: string
}
interface P2 {
p?: boolean
c?: any // if you replace c with string, error goes away
d?: any
}
declare var C: React.ComponentType<P1> | React.ComponentType<P2>
const a = <C p={true} /> // element does not have any ... It looks like, the problem is related to new "nullable discriminants" changes. Looks like ts can't find common interface for those types. interface P1 {
p?: any
c?: string // remove this and it's ok
}
interface P2 {
p?: boolean
} |
We have a similar problem, quick example: import * as React from 'react'
//
// Types
//
interface Config<P> {
ElementType: React.ReactType<P>
}
interface EmptyProps {
}
interface Props {
a?: string
}
type HProps = {
configEmpty: Config<EmptyProps>,
config: Config<Props>
}
//
// Component
//
const H: React.FC<HProps> = ({ config, configEmpty }) => {
const A: React.ReactType<EmptyProps> = configEmpty.ElementType // assigned
const B: React.ReactType<EmptyProps> = 'div' // assigned
const C: React.ReactType<Props> = config.ElementType // assigned
const D: React.ReactType<Props> = 'div' // in this case assignment failed
return (
<div>
<A/> {/* TS2604: JSX element type 'A' does not have any construct or call signatures. */}
<B/>
<C/>
<D/>
</div>
)
}
export default H I see this behaviour as completely invalid, because Code in repo: https://github.com/layershifter/ts-issue |
They do not, because you're using |
@Kovensky what about |
That is because I improved the type of |
@Kovensky thank you 👍 Now the issue with assignment is clear for me, but what about this? import * as React from 'react'
//
// Types
//
interface Config<P> {
ElementType: React.ReactType<P>
}
interface Empty {}
interface Props { a?: string }
type HProps = {
configEmpty: Config<Empty>,
config: Config<Props>
}
//
// Component
//
const H: React.FC<HProps> = ({ config, configEmpty }) => {
const A: React.ReactType<Empty> = configEmpty.ElementType // is React.ReactType<Empty>
const B: React.ReactType<Empty> = 'div' // is string
const C: React.ReactType<Props> = config.ElementType // is React.ReactType<Props>
return (
<div>
{/* React.ReactType<Empty> */} <A/> {/* <--- TS2604: JSX element type 'A' does not have any construct or call signatures. */}
{/* React.ReactType<Empty> */} <B/>
{/* React.ReactType<Props> */} <C/>
</div>
)
}
export default H
|
I would probably say @rexpan and @goloveychuk's error is similar to #28795 and #28768 based on conditional JSX constructor. |
Hm, so the issue is that For context, we effectively manufacture a type like this: declare const JsxSigs: {[K in keyof JSX.IntrinsicElements]: ((props: JSX.IntrinsicElements[K]) => JSX.Element)}[keyof JSX.IntrinsicElements]; which ends up as being a union of a ton of unique signatures. |
Before I changed it to be a union of all builtin jsx tags it was just |
Aye, especially since prior to 3.2, a |
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed for automatic house-keeping purposes. |
Running into a problem that might be related. I have the following component: function MaybeLabel(props: { useLabel: boolean }) {
const { useLabel } = props;
const TagName = useLabel ? 'label' : 'div';
return <TagName>Woookie</TagName>
} which results in
while function MaybeLabel2(props: { useLabel: boolean }) {
const { useLabel } = props;
const TagName = useLabel ? 'span' : 'div';
return <TagName>Woookie</TagName>
} is completely acceptable to the typescript compiler. As is: export function MaybeLabel3(props: { useLabel: boolean }) {
const { useLabel } = props;
const TagName = useLabel ? 'label' : 'div';
return React.createElement(TagName, 'Wookie')
} Where the only difference in Using latest version of @types/react and @types/react-dom, and verified the problem in typescript 3.2.1, 3.2.2 and 3.3.0-dev.20181219. In 3.1.6 it all works as expected (none of the examples produce errors) |
for me the solution was:
|
@TacB0sS please elaborate. |
I might have misunderstood the thread, but I wanted to pass a reference of a jsx Element to another jsx element: export const AppWrapper = hot(module)((props: WrapperProps) => {
const MainApp = props.mainApp;
if (!MainApp) // <-- JSX elements MUST start with upper case!!
throw new ImplementationMissingException("mainApp was not specified!!");
return (
<Router history={BrowserHistoryModule.getHistory()}>
<MainApp prop1={"value"}/>
</Router>)
}); Together with: export type WrapperProps = {
mainApp: React.ElementType<{prop1:string}>
} |
@TacB0sS For me the main trick was adding |
I'm not sure i understand the outcome of this. I have a similar error that I have not been able to resolve. Here is my use case:
and then I'm using it like such in another component like so:
When I run the compiler, i get this error:
Any ideas how to make this work? |
Instead of |
I got this error because I imported default but declared the corresponding export as named instead of default in the |
Just wanted to add this here. Not sure if this was already said but if you are doing a hirer order component you want to use the type React.ComponentType . "https://flow.org/en/docs/react/types/#toc-react-componenttype" |
@ericmasiello I ended up using type Props = {
heading: React.ElementType
}
const Header: FC<Props> = props => {
const Header = props.heading ?? 'h2';
return (
<Header className="some-class"><children /></Header>
)
} |
Cool! What version of Typescript and what version of @types/react do you have installed? |
|
I solved this problem by doing any of these two things: Case 1:.d.ts file: declare module "foo" {
interface PropFoo {
propy: string;
}
class MyTypedComponent extends React.Component<PropFoo> { }
} React: import MyTypedComponent from "foo";
function AnotherComponent() {
/* Notice in here we have to use the dot operator and reference the component */
return <MyTypedComponent.MyTypedComponent />
} Notice that, in order to use the newly typed component, we have to write MyTypedComponent.MyTypedComponent . This may be obvious to some people, but I wasted alot of time when all I had to do was to use the dot operator on the import and reference the component. Case 2 [just another way of writing Case 1]:.d.ts file: declare module "foo" {
interface PropFoo {
propy: string;
}
export default class MyTypedComponent extends React.Component<PropFoo> { } //Notice the export default in here
} React: import MyTypedComponent from "foo";
function AnotherComponent() {
/* Since this component is default exported, no need to use the dot operator */
return <MyTypedComponent />
} Soo, basically, check your exports, default exports, and imports and make sure you are referencing correctly. I'm very sorry for my English and I hope this helps. |
niu b |
ni zhe hui da ye nb haha |
When I write this code i get "JSX element type 'Header' does not have any construct or call signatures.ts(2604)" error. |
TypeScript Version: 3.2.0-rc, 3.2.1
Code
Expected behavior:
Should output normal as TypeScript 3.1.6
Actual behavior:
TS2604: JSX element type 'Comp' does not have any construct or call signatures.
The text was updated successfully, but these errors were encountered: