[英]Typescript & React/JSX: JSX element attributes type 'T' must be an object type
Using typescript 1.8.10 with VS 2015 and getting the following error while attempting to use react-router: 在VS 2015中使用打字稿1.8.10,并在尝试使用react-router时遇到以下错误:
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Router, browserHistory } from "react-router";
import routes from "./routes"; //get default
ReactDOM.render(
<Router routes={routes} history={browserHistory} />,
document.getElementById("app")
);
routes (from "./routes") 路线(来自“ ./routes”)
import App from "./components/App";
export default {
component: "div",
childRoutes: [{
path: "/",
component: App,
}]
};
error image: JSX element attributes type 'T' must be an object type 错误图片:JSX元素属性类型“ T”必须是对象类型
You aren't importing your routes object correctly. 您没有正确导入路由对象。 Since you are using
export default
you must use default import syntax : 由于您使用的是
export default
,因此必须使用默认导入语法 :
import routes from "./routes";
At this point, this error doesn't stop typescript from compiling your code down to JS so I'm just ignoring the error within the VS 2015 IDE. 此时,此错误不会阻止打字稿将代码编译为JS,因此我只是忽略了VS 2015 IDE中的错误。 It's really just an annoying red squiggly when it comes down to it...
归根结底,这确实是一个令人讨厌的红色...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.