【发布时间】:2021-04-19 17:08:00
【问题描述】:
我想将测试组件导入主页,但我不断收到以下错误:
Module '"/.../src/components/Test"' has no default export. Did you mean to use 'import { Test } from "/.../src/components/Test"' instead?
在测试组件中,我在导出测试时不断收到以下错误:
Type '({ name }: Props) => void' is not assignable to type 'FC<Props>'.
Type 'void' is not assignable to type 'ReactElement<any, any> | null'
测试组件
import React,{FC} from 'react';
interface Props {
name: string;
}
export const Test:FC<Props> = ({ name }: Props) => {
<div>{name}</div>
};
首页组件
import React from 'react';
import Test from './Test'
export const Home = () => {
<div><Test name="example" /></div>
};
tsconfig.json
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
}
【问题讨论】:
标签: javascript reactjs typescript tsx react-tsx