简体   繁体   English

Typescript&React / JSX:JSX元素属性类型“ T”必须是对象类型

[英]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.

相关问题 带有react-dnd的TypeScript 2.0会出现错误“JSX元素属性可能不是联合类型” - TypeScript 2.0 with react-dnd gives error “JSX element attributes may not be a union type” JSX元素属性类型[…]可能不是联合类型 - JSX element attributes type […] may not be a union type 哪种类型用于将JSX元素的属性抽象为对象? - What type would be used for abstracting a JSX element's attributes into an object? 反应 typescript 得到错误为 `Type '() =&gt; JSX.Element | 未定义'` - React typescript getting error as `Type '() => JSX.Element | undefined'` 在 TypeScript 中使用 JS React 组件:JSX 元素类型“MyComponent”不是 JSX 元素的构造函数 - Using JS React component in TypeScript: JSX element type 'MyComponent' is not a constructor function for JSX elements TypeScript、react-router 和 jsx:JSX 元素类型“Route”没有任何构造或调用签名 - TypeScript, react-router and jsx: JSX element type 'Route' does not have any construct or call signatures JSX 元素类型“字符串”不是 JSX 元素的构造函数 function。 Typescript - JSX element type 'string' is not a constructor function for JSX elements. Typescript react-beautiful-dnd / TypeScript - JSX 元素类型“DragDropContext”不是 JSX 元素的构造函数 - react-beautiful-dnd / TypeScript - JSX element type 'DragDropContext' is not a constructor function for JSX elements 打字稿错误 JSX 元素类型“视图”不是 JSX 元素的构造函数 - Typescript error JSX element type 'View' is not a constructor function for JSX elements JSX 中的 TypeScript 类型断言 - TypeScript Type Assertion in JSX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM