Closed bard closed 6 years ago
Having @types/react
alongside preact
is currently not supported by neither of those packages. Both declare the JSX
types globally which will clash with each other. For preact
this is tracked here https://github.com/developit/preact/issues/1036. As far as I know @types/react
don't have any short term plans to change that or perhaps no one has done a PR yet.
@marvinhagemeister forgive me if it's a dumb question, I'm relatively new to TypeScript, does that imply that (at least for now) preact-compat with TypeScript is a no-go and one should go with vanilla preact?
@bard preact
works fine with react
as long as you do not install @types/react
.
So, it appears I was barking wildly up the wrong tree. Parcel does its own resolution and aliasing modules is as easy as placing this in package.json
:
"alias": {
"react": "preact-compat",
"react-dom": "preact-compat"
}
Everything runs smoothly after that, even keeping @types/react
and @types/react-dom
installed.
Would you guys consider adding that bit to https://preactjs.com/guide/switching-to-preact?
@bard awesome, that's even better 🎉 Filed an issue over at preact-www
regarding our docs.
I want to alias
preact-compat
toreact
. I'm not using WebPack, I'm using Parcel which in turn is letting TypeScript do its own module resolution.I'm 50% there but type definitions are getting in the way (see below).
Details:
react
andreact-dom
are aliased topreact-compat
via thepaths
property intsconfig.json
:The compiler tries resolving
react
, looks atnode_modules/react
as per default, finds nothing, looks at the value ofpaths
above, triesnode_modules/preact-compat
, finds it and accepts it:So far, so good.
However if I install
@types/react
and retry the above...Ouch,
react
is now resolved to@types/react/index.d.ts
.How to keep types installed and still have
react
alias topreact-compat
?(I realize this is more of a TypeScript question but given the use case perhaps someone has come across and solved this already.)