ui icon indicating copy to clipboard operation
ui copied to clipboard

Property 'displayName' does not exist on type '...'

Open hoandt opened this issue 1 year ago • 2 comments

It seems that the displayName property is not directly assignable to the component in this case:

const Table = React.forwardRef< HTMLTableElement, React.HTMLAttributes<HTMLTableElement>

(({ className, ...props }, ref) => (

)) Table. displayName = "Table"

Property 'displayName' does not exist on type '(props: HTMLAttributes<HTMLTableElement> & RefAttributes<HTMLTableElement>) => ReactElement<any, string | JSXElementConstructor<...>> | null'.ts(2339)

Please guide me...

hoandt avatar Jun 04 '23 14:06 hoandt

I think it conflicts with ESLint or something. But I'm not sure how to fix it.

hoandt avatar Jun 04 '23 15:06 hoandt

I don't know, but I use this, it's fixed:

export const A = forwardRef(function A(props, ref) { return <>....</> });

hoandt avatar Jun 05 '23 02:06 hoandt

This issue has just popped up for me on all of my components.

I have no idea what I might have done to cause this.

Has anyone else encountered this and know how to fix?

brooksa-chemtest avatar Jul 03 '23 16:07 brooksa-chemtest

This issue also just popped up for me

brandnholl avatar Jul 03 '23 20:07 brandnholl

Fixed by adding semi-colons to the end of each display name declaration. MyComponent.displayName = 'MyComponent';

brandnholl avatar Jul 03 '23 20:07 brandnholl

No ideas. I leave them there.

Fixed by adding semi-colons to the end of each display name declaration. MyComponent.displayName = 'MyComponent';

Nice, but not working for me :(

hoandt avatar Jul 04 '23 01:07 hoandt

NO, I was stupid. I redeclared the forwardRef in global.d.types. Remove it and things will work again.... Man.. I'm crying

import * as React from "react";

declare module "react" { function forwardRef<T, P = {}>( render: (props: P, ref: React.Ref<T>) => React.ReactElement | null ): (props: P & React.RefAttributes<T>) => React.ReactElement | null; }

hoandt avatar Jul 04 '23 08:07 hoandt

Closed.

hoandt avatar Jul 04 '23 08:07 hoandt

I had this issue, then I updated all my packages and the errors were gone, super strange.

liuhe2020 avatar Jul 08 '23 21:07 liuhe2020

NO, I was stupid. I redeclared the forwardRef in global.d.types. Remove it and things will work again.... Man.. I'm crying

import * as React from "react";

declare module "react" { function forwardRef<T, P = {}>( render: (props: P, ref: React.Ref) => React.ReactElement | null ): (props: P & React.RefAttributes) => React.ReactElement | null; }

@hoandt Didn't get it can you explain how you solve it? I'm facing the same issue related "displayName" and I'm not able to deploy it on Vercel

usmanashrf avatar Jul 13 '23 10:07 usmanashrf

Can you try to find this in your entire project?

declare module "react" {

or

function forwardRef

hoandt avatar Sep 02 '23 16:09 hoandt

NO, I was stupid. I redeclared the forwardRef in global.d.types. Remove it and things will work again.... Man.. I'm crying

import * as React from "react";

declare module "react" { function forwardRef<T, P = {}>( render: (props: P, ref: React.Ref) => React.ReactElement | null ): (props: P & React.RefAttributes) => React.ReactElement | null; }

This is not working though, I already declare a module for this to override the forwardRef, but it was still getting me type error.

Property 'displayName' does not exist on type '(props: any) => ReactElement<any, string | JSXElementConstructor<any>>'

this is the error I got after declaring,

Hey, I found my own solution. Thanks!

declare module "react" { function forwardRef<T, P = {}>( render: (props: P, ref: React.Ref) => React.ReactElement | null ): (props: P & React.RefAttributes) => React.ReactElement | null; }


declare module "react" { function forwardRef<T, P = {}> ( render: (props: P, ref: React.Ref) => React.FunctionComponent | null ): (props: P & React.RefAttributes) => React.ReactElement | null; }

I don't know if this is the correct answer, but it works with me.

johnLamberts avatar Oct 05 '23 07:10 johnLamberts

I fixed it with "const App: React.FC"

kikienelsone avatar Apr 27 '24 04:04 kikienelsone