类型 'Context' 缺少类型 'Context<unknown>' 中的以下属性:提供者、消费者 TS2345

Exo*_*ist 2 typescript reactjs mobx

我正在尝试使用 rootstore 访问我的反应项目中的两个不同的商店。RoorStore.ts =>

import ExtractionStore from "./extractionStore";
import UserStore from "./userStore";
import { createContext } from "vm";

export class RootStore {
  extractionStore: ExtractionStore;
  userStore: UserStore;

  constructor() {
    this.extractionStore = new ExtractionStore(this);
    this.userStore = new UserStore(this);
  }
}

export const RootStoreContext = createContext(new RootStore());

Run Code Online (Sandbox Code Playgroud)

但是,在尝试将其注入我的组件时,出现错误:

组件 tsx =>

    const ExtractionDashboard: React.FC = () => {
      const rootStore = useContext(RootStoreContext);
      const { loadWorkList, loadingInitial } = rootStore.extractionStore;
Run Code Online (Sandbox Code Playgroud)

错误:

Argument of type 'Context' is not assignable to parameter of type 'Context<unknown>'.
  Type 'Context' is missing the following properties from type 'Context<unknown>': Provider, Consumer  TS2345

     7 | 
     8 | const ExtractionDashboard: React.FC = () => {
  >  9 |   const rootStore = useContext(RootStoreContext);
       |                                ^
    10 |   const { loadWorkList, loadingInitial } = rootStore.extractionStore;
    11 | 
    12 |   useEffect(() => {
Run Code Online (Sandbox Code Playgroud)

Tee*_*eez 9

您正在正确导入createContext函数

你有什么

import { createContext } from "vm";
Run Code Online (Sandbox Code Playgroud)

你应该拥有的

import { createContext } from "react";
Run Code Online (Sandbox Code Playgroud)