rajinwonderland / react-code-blocks

React code blocks and code snippet components
https://react-code-blocks.rajinwonderland.vercel.app
MIT License
613 stars 81 forks source link

Cannot run on react 17 + typescript #123

Closed quentin-decre closed 1 year ago

quentin-decre commented 1 year ago

I have not been able to make the CopyBlock run :

image

And when ignoring the ts error, it fail at runtime :

image

Any idea ?

DavidCibin commented 1 year ago

Kind of the same here. I can use CodeBlock just fine, but not the CopyBlock A simple test like this works fine <CodeBlock text="HELLO WORLD" />

But this, I get the warning below: <CopyBlock text="HELLO WORLD" />

TS2322: Type '{ text: string; }' is not assignable to type 'IntrinsicAttributes & ExecutionProps & RefAttributes<({ theme, text, codeBlock, customStyle, onCopy, ...rest }: CopyBlockProps) => Element>'. Property 'text' does not exist on type 'IntrinsicAttributes & ExecutionProps & RefAttributes<({ theme, text, codeBlock, customStyle, onCopy, ...rest }: CopyBlockProps) => Element>'.

I tried the version 0.1.4, 0.1.3 and then I went with the version as the one in the "CodeSandBox" which is the 0.0.8, and only this last one worked for me

xyba1337 commented 1 year ago

Kind of the same here. I can use CodeBlock just fine, but not the CopyBlock A simple test like this works fine <CodeBlock text="HELLO WORLD" />

But this, I get the warning below: <CopyBlock text="HELLO WORLD" />

TS2322: Type '{ text: string; }' is not assignable to type 'IntrinsicAttributes & ExecutionProps & RefAttributes<({ theme, text, codeBlock, customStyle, onCopy, ...rest }: CopyBlockProps) => Element>'. Property 'text' does not exist on type 'IntrinsicAttributes & ExecutionProps & RefAttributes<({ theme, text, codeBlock, customStyle, onCopy, ...rest }: CopyBlockProps) => Element>'.

I tried the version 0.1.4, 0.1.3 and then I went with the version as the one in the "CodeSandBox" which is the 0.0.8, and only this last one worked for me

If you're using nextjs >13.5.3 I highly advice you to not use the solution regarding the downgraded version, this just broke my entire project.

Fae-Bell commented 1 year ago

Pass in a theme. There is no default theme set.

It will still error in your IDE because there's a bug with how the properties are set up on the CopyBlock, but it will at least work. The error being that most props aren't optional, and the .d.ts is using: import("react").ForwardRefExoticComponent<import("styled-components").ExecutionProps & import("react").RefAttributes<typeof CopyBlock>> & {};

Both ExecutionProps and CopyBlock have a theme prop, and theme is optional in one, but required in the other

thomasmost commented 1 year ago

Hi y'all — I'm aware that this is an issue and will try and work on a fix this week. It's a bit of an arcane typing thing with the latest versions of Next and TS.

Very sorry for the inconvenience

thomasmost commented 1 year ago

I believe I've resolved this as of v0.1.5 — can someone confirm?

thomasmost commented 1 year ago

Finally got the fix published — again, sorry for the delay

Fae-Bell commented 1 year ago

Just to say it; The typescript issue I was seeing is fixed now. Looks like the types are set up properly.