Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

suppress TS2305 Module has no exported member error when using Typescript

Tags:

typescript

We start to use typescript with wechat mini program development. There is this annoying yet harmless error when we compile the project:

something like this

The project would still run, but because the quirk of wechat mini program/typescript, this error would persist. I tried using eslint-disable-line or eslint-disable with no effect...

Here is how to test/simulate it:

In file a:

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

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

Note, here we can't use:

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

because it is grammatically incorrect and we are not allowed to modify

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

(imagine they are injected code instead of codes you actually write)

and in file b, you have:

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

Note import { wx, App, Page } from 'file_a' must be on the top.

like image 278
Aero Wang Avatar asked Dec 01 '25 02:12

Aero Wang


1 Answers

Adding // @ts-ignore on top of import { wx, App, Page } from 'file_a'

like image 172
Aero Wang Avatar answered Dec 06 '25 06:12

Aero Wang