我正在使用 react dropzone 在我的简单应用程序中上传多张图片。为了显示要删除哪种类型的图像,我使用 TypeScript 制作了一个单独的组件。但 Next.js 图像 src 显示错误,如 Type:
'{ src: string; alt: string; }' is not assignable to type 'IntrinsicAttributes & ImageProps'.
Type '{ src: string; alt: string; }' is not assignable to type 'ObjectImageProps'.
Types of property 'src' are incompatible.
Type 'string' is not assignable to type 'StaticImport'.
渲染文件.ts:
import { IFile } from "../../libs/types";
import { sizeInMb } from "../../libs/sizeInMb";
import { FunctionComponent } from "react";
import Image from "next/image"
const RenderFile: FunctionComponent<{
file: IFile;
}> = ({ file: { formate, sizeInBytes, name } }) => {
return (
<div>
<Image src={`/images/${formate}.png`} alt="image"/>
<span>{name}</span>
<span>{sizeInMb(sizeInBytes)}</span>
</div>
);
};
export default RenderFile;
类型.ts:
export interface IFile {
name: string;
sizeInBytes: number;
formate: string | number;
id?: string;
}
我在 src 道具中的错误是什么?