Skip to content
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

Compat does not export all members that @types/react does #2414

Closed
ghost opened this issue Mar 12, 2020 · 7 comments
Closed

Compat does not export all members that @types/react does #2414

ghost opened this issue Mar 12, 2020 · 7 comments

Comments

@ghost
Copy link

ghost commented Mar 12, 2020

Reproduction

I'm currently attempting to use MobX (specificially, mobx-react-lite) in a Preact app, and I'm running into trouble with some of the interfaces it requires.

Versions

├── eslint-config-preact@1.1.0
├── preact@10.3.4
├── preact-cli@3.0.0-rc.10
├── preact-feather@4.1.0
├── preact-render-to-string@5.1.4
├── preact-router@3.2.1

Steps to reproduce

Wrapping a MobX observer around a functional component will cause this issue:

import { FunctionalComponent, h } from 'preact';
import { observer as mobxObserver } from "mobx-react-lite";

function observer<P>(props: P) {
  return mobxObserver(props as any);
}

const ExampleComponent: FunctionalComponent = observer(() => { 
... 
});

Expected Behavior

The app should be able to be built.

Actual Behavior

I received this error after trying to do a production build of the app (note: it does work as expected in develop):

✖ ERROR ./node_modules/mobx-react-lite/dist/observer.d.ts
ERROR in ./node_modules/mobx-react-lite/dist/observer.d.ts(5,84):
TS2694: Namespace 'React' has no exported member 'RefForwardingComponent'.

After opening up node_modules/mobx-react-lite/dist/observer.d.ts, this is what I found:

export declare function observer<P extends object, TRef = {}>(baseComponent: React.RefForwardingComponent<TRef, P>, options: IObserverOptions & {
    forwardRef: true;
}): React.MemoExoticComponent<React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<TRef>>>;

There are errors on RefForwardingComponent, MemoExoticComponent, PropsWithoutRef, and RefAttributes, as none of these items are exported from compat's React namespace.

My question is how do I solve this, or is this something I can even solve on my own end?

@klaemo
Copy link

klaemo commented Mar 24, 2020

This might be related to #1930 and #2329

@atcq-me
Copy link

atcq-me commented Mar 28, 2020

I have the same problem after mobx-react 6.1.8.

@ForsakenHarmony
Copy link
Member

We've had a couple of issues about this, so I'll close this one for now

Here's a possible workaround
#2150 (comment)

@ForsakenHarmony
Copy link
Member

If you could try out the changes in #2329 and report there if that fixes it that would also help

@ghost
Copy link
Author

ghost commented Mar 28, 2020

Neither of those actually export even 1 out of the 4 interfaces needed, so they both fail, while the first solution starts to break other libraries too.

I don't quite see how this can be closed when no solution is offered that works.

@ForsakenHarmony
Copy link
Member

cause it's very similar to existing issues, it's not closed because it's solved

i.e. #2222

@matthias-ccri
Copy link

Workaround here: #2150 (comment). You may need to customize it. I agree it's not a great situation, so please upvote the issues, both this one and #2222 and #2150.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants