这是我在Hello.tsx中的第一部分代码:
import * as React from "react";
export interface HelloProps { compiler: string; framework: string; }
const Hello = (props: HelloProps) => <h1>Hello from {props.compiler} and {props.framework}!</h1>;
export default Hello;
我正在尝试将其导入index.tsx中:
import * as React from "react";
import * as ReactDOM from "react-dom";
import { Hello } from "./components/Hello";
ReactDOM.render(
<Hello compiler="TypeScript" framework="React" />,
document.getElementById("example")
);
但是我有一个:
模块'“ ./components/Hello”'没有导出的成员'Hello'.ts(2305)
错误。
答案 0 :(得分:1)
您正在将Hello
导出为默认导出,但是将其导出为命名导出。
相反,可以使用以下这一行将其导入为默认导出:
import Hello from "./components/Hello";
或通过摆脱export default Hello;
并将其导出为命名输出,导出为:
export const Hello = (props: HelloProps) => <h1>Hello from {props.compiler} and {props.framework}!</h1>;