How to properly alias Preact/compat with TypeScript?
See original GitHub issueReproducing
git clone https://github.com/talentlessguy/preact-emotion-ts.git
yarn install
- Open vscode, with these settings:
{
"eslint.packageManager": "yarn",
"npm.packageManager": "yarn",
"editor.formatOnSave": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"editor.suggestSelection": "first",
"eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": true,
"prettier.configPath": "/home/v1rtl/.prettierrc.yml",
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
And see this error on <Header>
component:
JSX element type 'Header' does not have any construct or call signatures.
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 this
preact-emotion-ts is 📦 v1.0.0 via ⬢ v13.2.0
❯ npx eslint src/*.tsx --fix
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
I don’t what the issue is coming from but I suppose it is a problem with typings of preact (?)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:17 (6 by maintainers)
Top Results From Across the Web
TypeScript | Preact: Fast 3kb React alternative with the same ...
TypeScript configuration; TypeScript preact/compat configuration; Typing components ... This way, your alias will work properly when libraries import React.
Read more >react native - How to create typings alias in typescript the way ...
Take for example, preact is a lib with API highly resembles one of react . Say you write your code using react and...
Read more >Module Resolution - Parcel
Aliases are supported through the alias field in package.json . This example aliases react to preact and some local custom module that is...
Read more >Using Styled components with Preact | Momchil Georgiev
We need to do some “magic” called aliasing, so that when Styled looks for React it gets Preact compatibility instead.
Read more >Building a Typescript Environment for Preact with Vite
Building a Typescript Preact environment using the No bundle tool Vite, along with ... It should work, but I'll add a few more...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ForsakenHarmony thanks, it works now!
my final react.d.ts is like this:
there are only 3 warnings about JSX namespace but VS Code doesn’t complain about them:
Closing the issue 👍
I just remembered I used emotion at some point
https://github.com/ForsakenHarmony/sky1/blob/master/frontend/typings/react/index.d.ts I have react aliased with preact exports