【问题标题】:why is my class undefined when exported like this?为什么像这样导出时我的类未定义?
【发布时间】:2019-09-06 14:04:47
【问题描述】:

文件夹结构

├── shared/
│   ├── index.ts
│   ├── formatters.ts
│   ├── validators.ts
|   ├── package.json

独立项目

├── project/
│   ├── project.ts
│   ├── package.json

格式化程序

export class A{
}
export class B{
}

验证器

export class C{
}

index.ts

export * from './validators'
export * from './formatters'

project.ts(通过 npm 安装共享)

import {A} from 'shared'
console.log(A) //undefined

如果我让索引文件看起来像这样

export { C } from './validators'
export { A, B } from './formatters'

然后就可以了

【问题讨论】:

    标签: typescript


    【解决方案1】:

    原来构建工作不正常。我不知道为什么,但是构建的 index.js 文件中没有注册导入

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-13
      • 2020-10-01
      相关资源
      最近更新 更多