Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declaration emit for this file requires using private name X from module ... #61

Open
hughfenghen opened this issue Dec 25, 2020 · 0 comments

Comments

@hughfenghen
Copy link
Owner

hughfenghen commented Dec 25, 2020

使用tsc给js项目生成声明文件时(d.ts)抛出这个错误。
tsc --declaration lib/index.js --allowJs --emitDeclarationOnly --declarationDir dts

原因是commonjs模块,使用class声明两个类并导出了(exports):

class A {}
class B {}
module.exports = {
  A,
  B,
}

两个方式可绕开这个问题:
改成

class A {}
class B {}
module.exports.A = A
module.exports.B = B

或者改成

const A = class {}
const B = class {}
module.exports = {
  A,
  B,
}

typescript版本: 4.1.3

相关issue microsoft/TypeScript#37832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant