-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
How to properly alias Preact/compat with TypeScript? #2150
Comments
The reason behind |
okay, thanks for pointing out the issue.
|
This seems to be related to us missing the deprecated |
But I don't use If there is no any option with using pure Preact and Emotion, I can alias it |
The purpose of |
@JoviDeCroock okay, then I'll just stick to Closing the issue |
Update: Even when aliasing to preact/compat in {
"compilerOptions": {
"outDir": "./dist",
"sourceMap": true,
"noImplicitAny": true,
"module": "es6",
"moduleResolution": "node",
"target": "es6",
"jsx": "react",
"baseUrl": ".",
"paths": {
"react": ["node_modules/preact/compat"],
"react-dom": ["node_modules/preact/compat"]
},
"allowSyntheticDefaultImports": true
},
"include": ["./src/**/*"]
} I still get this error (and new ones):
Full log here: https://termbin.com/r9vr I guess I messed up somewhere in aliasing |
Your tsconfig is excluding paths from taking effect in Secondly to make parcel work you'll have to add
To |
okay, I removed module resolution from tsconfig.json yeah, I have it aliased, so it builds fine (using
|
Well that's not really the solution, it goes recursively into |
@JoviDeCroock no problem, I can wait Thanks for spending time on my issue btw ❤️ |
I just remembered I used emotion at some point https://github.com/ForsakenHarmony/sky1/blob/master/frontend/typings/react/index.d.ts |
@ForsakenHarmony thanks, it works now! my final react.d.ts is like this: import {
AnyComponent,
createElement,
FunctionalComponent,
RenderableProps,
ComponentChild
} from 'preact'
export {
Attributes,
FunctionalComponent as SFC,
AnyComponent as ComponentType,
AnyComponent as JSXElementConstructor,
Component as ComponentClass,
ClassAttributes,
PreactContext as Context,
PreactProvider as Provider,
VNode as ReactElement,
VNode as ReactNode,
createElement,
Fragment,
Ref,
render,
JSX,
RenderableProps as ComponentPropsWithRef
} from 'preact'
// export type JSXElementConstructor = AnyComponent; there are only 3 warnings about JSX namespace but VS Code doesn't complain about them:
Closing the issue 👍 |
As for |
For Because according to @types/react, ReactNode includes export {
...
ComponentChild as ReactNode,
// Also:
Component as PureComponent,
...
} from 'preact'; For the record, this is how to use the
|
I had similar problems when compiling tsx because on of the dependencies - react-leaflet uses react types extensively. I was successful with a modified version of @types/react (without the JSX namespace), but then decided to just set |
@talentlessguy Small correction:
import {
AnyComponent,
createElement,
FunctionalComponent,
RenderableProps,
ComponentChild,
ComponentChildren
} from 'preact'
export {
Attributes,
FunctionalComponent as SFC,
AnyComponent as ComponentType,
AnyComponent as JSXElementConstructor,
Component as ComponentClass,
ClassAttributes,
PreactContext as Context,
PreactProvider as Provider,
VNode as ReactElement,
createElement,
Fragment,
Ref,
render,
JSX,
RenderableProps as ComponentPropsWithRef
} from 'preact'
export type ReactNode = ComponentChild | ComponentChildren;
// export type JSXElementConstructor = AnyComponent; |
Reproducing
git clone https://github.com/talentlessguy/preact-emotion-ts.git
yarn install
And see this error on
<Header>
component:Versions
emotion: 10.0.22
preact: 10.0.5
eslint: 6.7
typescript: 3.7.2
Screenshot
The weirdiest thing is that
npx eslint
doesn't show anything like thisI don't what the issue is coming from but I suppose it is a problem with typings of preact (?)
The text was updated successfully, but these errors were encountered: