在打字稿中导入 svg 图像

Importing an svg image in typescript

使用下面的代码作为示例,它运行完美,打字稿编译器正在为“import logo from './images/logo.svg';”语句而哭泣。该应用程序在浏览器中 运行 时运行完美,因此我没有遇到任何功能问题。我只想去掉波浪形的红线,这样我就可以清理我的目录查看器了。任何帮助将不胜感激。

import * as React from 'react';
import logo from './images/logo.svg';

interface Property {}
interface State {} 

export default class App extends React.Component<Property, State> { 
    render() {
        return (
            <div className="App">
                <div className="App-header">
                    <img src={logo} className="App-logo" alt="logo" />                        
                </div>      
            </div>
        );
    }
}

在您的任何输入文件中添加 declare module '*.svg'。 (.d.ts)