reactjs - 通用型別 'Component
' 需要 2 個型別參數
我正在嘗試使用 ts 和 react-router v4 來製作一個示範,但我會遇到錯誤。
Failed to compile.
Error in D:\data\code\taven\react-components-usage-ts\node_modules\@types\react-router\lib\withRouter.d.ts
(3,99): error TS2314: Generic type 'PureComponent<P, S>' requires 2 type argument(s).
答案#1
我也看到了這個錯誤。這個錯誤是在兩週前的最新版本 4.0.12 中出現的。請使用之前的版本。在那個版本中一切正常運作。
npm install --save @types/[email
react-route-dom 也發生了同樣的情況。使用:
npm install --save @types/[email
答案#2
你在組件上方缺少 props 和 state 的介面。
interface P {
sampleProp: string,
awesomeProp2: number
}
interface S {}
PureComponent<P, S>
