typescript - 在生成的 commonjs 包中需要时如何避免使用点表示法访问默认导出的类实例
问题描述
我在 TypeScript 文件中导出一个类实例,如下所示:
索引.ts
export { myClient } from './my-client.ts'
我的客户.ts
class myClient {
}
export const myClient = new myClient();
然后我将其编译为 es5 格式的 commonjs,当我在节点中使用它时,我必须像这样访问它:
const myClient = require('myclient').myClient;
虽然这可行,但有没有一种方法可以让我在不需要使用.myClient
符号的情况下要求和使用我的课程?
更新
我尝试在我的 TS 文件中更改我的类实例的导出:
索引.ts
export { default as myClient } from './my-client.ts'
我的客户.ts
class myClient {
}
const myClient = new myClient();
export default myClient;
但是我仍然必须在我的节点应用程序中像这样访问:
const myClient = require('myclient').myClient;
解决方案
推荐阅读
- r - R中复杂多项式(右偏函数)的最大似然参数估计
- julia - JuliaPro:错误:系统错误:无法读取目录操作不允许
- javascript - 为什么我的 ul 中的所有项目都没有显示?
- python - “gcloud beta 计算实例更新容器”的 python 代码
- php - 如何访问不同位置的同一个文件
- git - 回购的所有者如何进行拉取请求?
- javascript - TypeScript 错误告诉我“'GatsbyImage' 类型上不存在属性 'fluid'”
- python - 如何从字符串中取出非字母字符并以相同的顺序将它们放回字符串中?
- python - 抓取 wsj.com 时页面上的元素不存在
- python - 如何将 jsonreader 对象转换为 Python Dataframe?