Skip to content

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

Description

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?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions