gpt4 book ai didi

typescript - 下一个图像的类型定义

转载 作者:行者123 更新时间:2023-12-05 09:13:05 27 4
gpt4 key购买 nike

我将 typescript 与 NextJs 和 next-images 一起使用。代码是:

import css from "./style.sass";
import img from './logo.svg';
import Link from 'next/link';

export default () => <Link href="/">
<img src={img} className={css.logo}/>
</Link>;

如果没有输入,则会显示此错误:

Cannot find module './logo.svg'.ts(2307)

目前我使用以下类型(typings.ts):

declare module "*.svg" {
const value: string;
export default value;
}

declare module "*.png" {
const value: string;
export default value;
}

declare module "*.jpg" {
const value: string;
export default value;
}

使用这些 typings.ts 文件应该可以解决错误,但事实并非如此。有人在使用时遇到同样的错误吗?有没有更好的方法来编写 typings.ts 文件?

最佳答案

2020 年更新:

下一个图像包现在支持 TypeScript。

您需要做的就是在 next-env.d.ts 中添加定义

https://github.com/twopluszero/next-images#typescript

关于typescript - 下一个图像的类型定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56710038/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com