【问题标题】:suppress TS2305 Module has no exported member error when using Typescript使用 Typescript 时抑制 TS2305 模块没有导出成员错误
【发布时间】:2019-11-28 02:43:42
【问题描述】:

我们开始使用打字稿和微信小程序开发。当我们编译项目时,会出现这个烦人但无害的错误:

项目还是会运行,但是因为微信小程序/打字稿的怪癖,这个错误会一直存在。我尝试使用eslint-disable-lineeslint-disable 没有效果...

这是测试/模拟它的方法:

在文件a中:

const App = () => {};
const Page = () => {};
const wx = {}, _wx = { App, Page };

module.exports = {
  wx: { ...wx, ..._wx },
  App: _wx.App,
  Page: _wx.Page
}

注意,这里我们不能使用:

export {
   wx: { ...wx, ..._wx },
   App: _wx.App,
   Page: _wx.Page
}

因为它在语法上不正确,我们不允许修改

const App = () => {};
const Page = () => {};
const wx = {}, _wx = { App, Page };

(想象它们是注入代码而不是您实际编写的代码)

在文件 b 中,你有:

import { wx, App, Page } from 'file_a'
import ... from '...'

注意import { wx, App, Page } from 'file_a'必须在顶部。

【问题讨论】:

    标签: typescript


    【解决方案1】:

    import { wx, App, Page } from 'file_a'之上添加// @ts-ignore

    【讨论】:

    • 我建议您添加一条关于您要忽略的确切内容的评论,例如 // @ts-ignore: has no exported member 'wx'
    猜你喜欢
    • 2020-11-13
    • 2017-03-29
    • 2021-12-20
    • 2022-01-16
    • 2021-03-25
    • 2022-01-18
    • 2018-09-04
    • 2017-06-13
    • 2019-02-02
    相关资源
    最近更新 更多