我有一个新的 .tsx 文件,我希望将标题传递给我的组件。但是,属性“title”使用下面的简单代码返回以下错误。
输入'{标题:字符串;}' 不可分配给类型 'IntrinsicAttributes & String'。“IntrinsicAttributes & String”类型上不存在属性“title”。TS2322
import React from 'react';
import { render } from 'react-dom';
import { Nav } from "./sections";
render(
<Nav title="Suite" />,
document.getElementById('root')
);
我的 Nav 组件的代码如下:
import React from "react";
export const Nav = (title: String) => {
return <ul><li>{title}</li></ul>;
};
我仍在进行故障排除,我想知道修复是否与我的 TSConfig 有关。任何建议都会受到欢迎。
如果这有帮助,这是我的 tsconfig.json 的副本
{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}