-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Using Mobx-React works with Preact Watch, but not Preact Build #953
Comments
Yes building is what does a more thorough type checking. This seems like a bug in Preact core typings and nothing to do with CLI specifically |
Should I then move this over to the Preact repository instead? |
This is a known issue with TS. It doesn't allow anyone to alias typing packages and thus a library written for But then you're still faced with the issue of mixing both React with Preact types. The only solution to that I've seen so far is re-casting the type. Something like the following pseudo code (currently on mobile). You should get the idea: import { observer as mobxObserver } from "mobx-react-lite";
// Re-typing functions with generics by assigning them to variables
// doesn't seem to work, so we create a new function :/
function observer<P>(props: P) {
return mobxObserver(props as any);
} If somebody knows a better solution to this I'd love to hear it. This would help us a lot, because it's a frequent question we get over at the Preact issue tracker. |
The other solution is writing your own |
Do you want to request a feature or report a bug?
Bug (I believe)
What is the current behaviour?
I'm using mobx and mobx-react-lite to add global state to my TypeScript Preact project, and I'm using the functional component syntax, so a component with mobx looks something like
const component: preact.FunctionalComponent = observer(() => { ... });
.This works as expected while running the development server (
preact watch
), fully functioning, no problems. However, if I try to build the project withpreact build
, I'm given the following error:Odd that only building needs the types, but okay. So I install
@types/react
, but I'm then met with:As I understand it, the preact.VNode is incompatible with whatever type is defined in
@types/react
, which does make sense, as React has it's own Node type.But how exactly do I get around this? I assume because the dev server works, this is an error with the aliasing, but only with the build script.
If the current behaviour is a bug, please provide the steps to reproduce.
Wrap a component with
mobx-react-lite
'sobserver
while using TS:What is the expected behaviour?
I'd expect to be able to build the application without experiencing that type issue. Again, not an expert here, but I believe this is due to an alias not being properly resolved, so I'd like to make sure this works.
Please mention other relevant information.
My config file:
Result from running
preact info
:The text was updated successfully, but these errors were encountered: