preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.41k stars 1.93k forks source link

VSCode/TypeScript: JSX element type 'Component<{}, {}>' is not a constructor function for JSX elements. #1671

Open IngwiePhoenix opened 5 years ago

IngwiePhoenix commented 5 years ago

image

I am new to TypeScript and basically moved to it due to a much more stable support for decorators, some frameworks and since I am generally more into typed languages like C/C++.

So when I began to put together a basic example with 10.0.0-beta.2, I got the error seen in the screenshot above.

Is that something I need to worry about - or rather, something that I can do anything about? Thanks!

ForsakenHarmony commented 5 years ago

I think that might be a conflict between react and preact types

Silic0nS0ldier commented 5 years ago

I've hit another type incompatibility issue myself.

src/app.tsx:6:2 - error TS2605: JSX element type 'PrimaryButton' is not a constructor function for JSX elements.
  Types of property 'componentDidCatch' are incompatible.
    Type '(error: Error, errorInfo: ErrorInfo) => void' is not assignable to type '(error: any) => void'.

6  <PrimaryButton>I am a button.</PrimaryButton>

Would it be at all possible to expand the preact type definitions to use the existing widely used definitions distributed via @types/react?

pmkroeker commented 5 years ago

Both of these problems should be resolved with #1703

KashubaK commented 5 years ago

Running into this problem on 10.0.0-rc.0. I have a typescript project that requires me to render preact components inside a react project, and whenever I do this I get the same error as OP.