TypeScript版本: 3.0.1
搜索词: 找不到名称导入默认值
代码
// fetch.d.ts
declare function fetch(url: string): Promise<any>;
export = fetch;
declare namespace fetch {
export { fetch as default };
}
// index.ts
import f from "./fetch";
f("url"); // error TS2304: Cannot find name 'f'
预期行为: 应该找到名称
实际行为: 找不到名称。有趣的是,import { default as f } from "./fetch";
可以正常工作。
** playground链接:** (它不支持模块:/)
相关问题: 没有找到一个
1条答案
按热度按时间sf6xfgos1#
我也遇到了从js文件中默认导入的问题,
exports.default = Component
。import Component from '...'
在2.8.4
版本中运行正常,现在只在import {default as Component} from '...'
版本中运行。我的
tsconfig
中有"allowSyntheticDefaultImports": true
,将设置选项更改为false
可以解决这个问题,但会在我的项目中带来更多的麻烦。这可能是相关问题。