首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >泛型类型“Dispatch<S>”需要1个类型参数。TS2314

泛型类型“Dispatch<S>”需要1个类型参数。TS2314
EN

Stack Overflow用户
提问于 2020-04-08 17:00:14
回答 1查看 274关注 0票数 0

我在我的Mac上克隆了一个react项目,它可能是在Windows下开发的。

我做了yarn add react-scriptsyarn installpackage.json如下所示。然后,PORT=8000 ./node_modules/.bin/react-scripts start返回以下错误。

有人知道怎么解决这个问题吗?

代码语言:javascript
复制
Failed to compile.

/Users/chengtie/Startup/PRODSERVER/tmp/10Studio/frontend/src/components/NoAuthLoginRedirect/index.tsx
TypeScript error in /Users/chengtie/Startup/PRODSERVER/tmp/10Studio/frontend/src/components/NoAuthLoginRedirect/index.tsx(18,13):
Generic type 'Dispatch<S>' requires 1 type argument(s).  TS2314

    16 | import { getAppSubscribePage } from '../../services/app-utils';
    17 | export interface INoAuthLoginRedirectProps {
  > 18 |   dispatch: Dispatch;
       |             ^
    19 |   onDissmiss?: Function;
    20 |   next?: string;
    21 |   subscription?: Subscription;

package.json

代码语言:javascript
复制
{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.9.8",
    "@microsoft/office-js-helpers": "^1.0.2",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/react-stripe-elements": "^6.0.4",
    "@uifabric/react-cards": "^0.109.49",
    "axios": "^0.19.2",
    "color": "^3.1.2",
    "cross-storage": "^1.0.0",
    "dva": "^2.4.1",
    "dva-model-creator": "^0.4.3",
    "formik": "^2.1.4",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "monaco-editor": "^0.20.0",
    "node-sass": "^4.13.1",
    "office-ui-fabric-react": "^7.105.4",
    "query-string": "^6.11.1",
    "react": "^16.13.1",
    "react-app-polyfill": "^1.0.6",
    "react-dom": "^16.13.1",
    "react-monaco-editor": "^0.35.0",
    "react-scripts": "^3.4.1",
    "react-stripe-elements": "^6.1.1",
    "redux-devtools-extension": "^2.13.8",
    "start": "^5.1.0",
    "styled-components": "^5.0.1",
    "typescript": "^3.8.3",
    "yup": "^0.28.3"
  },
  "scripts": {
    "start": "SET PORT=8000 && react-scripts start",
    "build": "react-scripts --max_old_space_size=8096 build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/color": "^3.0.1",
    "@types/cross-storage": "^0.8.29",
    "@types/jest": "^25.1.4",
    "@types/lodash": "^4.14.149",
    "@types/node": "^13.9.5",
    "@types/query-string": "^6.3.0",
    "@types/react": "^16.9.27",
    "@types/react-dom": "^16.9.5",
    "@types/react-redux": "^7.1.7",
    "@types/styled-components": "^5.0.1",
    "@types/yup": "^0.26.33"
  }
}

下面是index.tsx一部分

代码语言:javascript
复制
import React from 'react';
import { connect } from 'dva';
import { Dispatch } from 'redux';
import { push } from 'react-router-redux';

import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
import { Dialog, getId, DialogType, Stack, Text } from 'office-ui-fabric-react';

import { State } from '../../store/reducer';
import { getNextPath } from '../../selectors/header';
import { getSubscription, getTrial } from '../../selectors/subscription';
import { Subscription } from '../../services/subscription';
import { getIsSubscriptionActive, getPlanProductName } from '../Plans/utils';
import { selectAppName } from '../../selectors/app';
import { AppName } from '../../models/app';
import { getAppSubscribePage } from '../../services/app-utils';
export interface INoAuthLoginRedirectProps {
  dispatch: Dispatch;
  onDissmiss?: Function;
  next?: string;
  subscription?: Subscription;
  trial: Subscription;
  feature: string;
  app: AppName;
}
EN

回答 1

Stack Overflow用户

发布于 2020-04-09 17:28:53

好吧,问题是'Dispatch‘类型是泛型的,但是你没有给它提供一个类型。

确保导入来自您实际需要的模块,因为“Dispatch”也可以在您意外导入的模块中使用。

除此之外,要快速修复它,您可以将

代码语言:javascript
复制
dispatch: Dispatch;

转到

代码语言:javascript
复制
dispatch: Dispatch<any>;

看看这个应用能不能编译。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61096950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档