Preact: refs is missing in declaration file

Created on 8 Sep 2018  路  7Comments  路  Source: preactjs/preact

I have noticed that having both preact and react types (@types/react) will confuse the typescript compiler and throw the following error:

'Property 'refs' is missing in type 'component'.'

apparently, the property 'refs' is missing from the 'preact.d.ts' declaration file.

adding the following code after line 101 in 'preact.d.ts' will solve the problem:

refs: { [key: string]: Component<any> | Element; };

tried to submit a PR, but couldn't find the file mentioned.

Thanks

Most helpful comment

I ran into same problem. I'm using @types/react-beautiful-dnd and @types/react-redux, it installs @types/react.

I think @developit should reopen this issue

All 7 comments

What is the reason for using both type definitions at the same time?

we are using Lerna for creating an application with multiple packages, most of the packages are using react, and we are going to migrate them to Preact, they all using same 'node_modules' and that's why it confuses the compiler.

also to mention that it is not necessary to fix this problem, as we will eventually migrate to preact. but what would be a reason for not having the 'refs' in declaration file?

I stumbled into the same problem using preact and react-redux. connect from react-redux uses reacts type definitions and expects my component to have refs.
Is downgrading to some non-latest version of react-redux an option?

I ran into exactly same problem. I'm not using \@types/react. I could compile but VS code says it's error.
@Cyrus-d 's solution helped me.

I ran into same problem. I'm using @types/flux, it installs @types/react to my node_modules and conflicts to preact.

I ran into same problem. I'm using @types/react-beautiful-dnd and @types/react-redux, it installs @types/react.

I think @developit should reopen this issue

For reference, installing storybook types will also install React types and confuse the compiler. If you're using Babel 7 you should switch to the TypeScript Babel plugin which simply doesn't check for types on build, or do without Storybook types.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcosguti picture marcosguti  路  3Comments

adriaanwm picture adriaanwm  路  3Comments

paulkatich picture paulkatich  路  3Comments

k15a picture k15a  路  3Comments

matthewmueller picture matthewmueller  路  3Comments