我正在尝试像这样扩展react-router路由器类:
class RouterWrapper extends Router {
componentWillMount() {
super.componentWillMount();
}
}
所以我有一个打字稿编译错误
TS2339: Property 'componentWillMount' does not exist on type 'Component<RouterProps, ComponentState>'
。安装所有必要的类型。
现在我找到了解决方法:
class PatchRouter extends Router {
componentWillMount?();
}
然后从PatchRouter
延伸,但这个解决方案太难看了。
所以,这是我的问题: 如何正确扩展路由器使用typescript 2.2?
我的package.json
{
"name": "react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "cross-env NODE_ENV=development node dev-server.js",
},
"author": "",
"license": "ISC",
"dependencies": {
"cross-env": "^3.1.3",
"express": "^4.14.0"
},
"devDependencies": {
"@types/history": "^2.0.45",
"@types/react": "^15.0.0",
"@types/react-dom": "^0.14.19",
"@types/react-router": "^2.0.44",
"core-js": "^2.4.1",
"dom-helpers": "^3.2.0",
"jss": "^6.2.0",
"jss-camel-case": "^3.0.0",
"jss-default-unit": "^5.0.2",
"jss-nested": "^3.0.1",
"jss-vendor-prefixer": "^4.0.0",
"memory-fs": "^0.4.1",
"mobx": "^3.0.1",
"mobx-react": "^4.1.0",
"mobx-react-devtools": "^4.2.11",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-hot-loader": "^3.0.0-beta.6",
"react-router": "^3.0.1",
"ts-loader": "^1.3.0",
"tslib": "^1.5.0",
"typescript": "^2.2.0-dev.20161208",
"url-loader": "^0.5.7",
"webpack": "^2.2.0-rc.6",
"webpack-dev-middleware": "^1.9.0",
"webpack-hot-middleware": "^2.14.0"
}
}