有人可以帮我解决以下问题:
创建React.Component类时,我收到以下错误消息:
代码:
import * as React from 'react';
export default class App extends React.Component<{}, {}> {
}
错误:为简洁省略了某些事项(请参阅图片中的完整错误)
通用类型&#39; $ $ RsRpExt&#39;来自file&#39; ... \ @ types \ react \ index.d.ts,module = JavascriptReferencedFilesModules外部文件&#34; .React.Component需要1个类型的参数但是得到2
在 index.d.ts 文件中:
//
// Component API
// ----------------------------------------------------------------------
type ReactInstance = Component<any> | Element;
// Base component for plain JS classes
// tslint:disable-next-line:no-empty-interface
interface Component<P = {}, S = {}> extends ComponentLifecycle<P, S> { }
class Component<P, S> {
constructor(props: P, context?: any);
// We MUST keep setState() as a unified signature because it allows proper checking of the method return type.
// See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257
// Also, the ` | S` allows intellisense to not be dumbisense
setState<K extends keyof S>(
state: ((prevState: Readonly<S>, props: P) => (Pick<S, K> | S)) | (Pick<S, K> | S),
callback?: () => any
): void;
forceUpdate(callBack?: () => any): void;
render(): ReactNode;
// React.Props<T> is now deprecated, which means that the `children`
// property is not available on `P` by default, even though you can
// always pass children as variadic arguments to `createElement`.
// In the future, if we can define its call signature conditionally
// on the existence of `children` in `P`, then we should remove this.
props: Readonly<{ children?: ReactNode }> & Readonly<P>;
state: Readonly<S>;
context: any;
refs: {
[key: string]: ReactInstance
};
}
我的 tsconfig.json 文件:
{
"name": "timeregistration",
"version": "1.0.0",
"description": "",
"main": "./wwwroot/src/index.tsx",
"dependencies": {
"@types/react": "^16.0.31",
"@types/react-dom": "^16.0.3",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.6"
},
"devDependencies": {
"awesome-typescript-loader": "^3.4.1",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"source-map-loader": "^0.2.3",
"typescript": "^2.6.2",
"webpack": "^3.10.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"watch": "webpack -w"
},
"author": "Jan Somers",
"license": "ISC"
}
谢谢:)