在create-react-app中,我将一个工作的jsx文件转换为tsx文件,以下是需要转换的代码行:
import { ReactComponent as Logo } from "./logo.svg";
出现了typescript错误:无法找到模块'./logo.svg'或其对应的类型声明.ts(2307)
在tsconfig.json中我添加了如下内容:
{
"include": ["src", "./src/**/*.ts", "./src/**/*.svg"]
}
看起来 node_modules/react-scripts/lib/react-app.d.ts 已经有了:
declare module '*.svg' {
import * as React from 'react';
export const ReactComponent: React.FunctionComponent<React.SVGProps<
SVGSVGElement
> & { title?: string }>;
const src: string;
export default src;
}
所以我不确定问题出在哪里。
这个SVG的开头是以下内容:
<svg xmlns="http://www.w3.org/2000/svg" height="100" width="100"><path d="M38.0
--template typescript
的create-react-app引起的吗? - Ryuujo