我正在开发可扩展另一个的程序包。我希望客户只能依赖我的一个子程序包,而且还可以从父程序包访问类型,接口等。因此,我不希望客户同时依赖我的子程序包和父程序包。如何从子包中导出或传递父包?
我尝试设置一个index.ts
来导出包,但是在编译时,index.js
中省略了export语句,并且在父包中找不到代码。编译输出目录。
package.json
:
"name": "@parent_scope/parent_package",
"version": "1.0.0",
"main": "dist/index.js"
main.ts
:
export interface ParentInterface {
property: any
}
index.ts
:
export { ParentInterface } from './main';
package.json
:
"name": "@child_scope/child_package",
"version": "1.0.0",
"main": "dist/index.js",
"dependencies": {
"@parent_scope/parent_package": "1.0.0"
}
main.ts
:
export interface ChildInterface {
property: any
}
index.ts
:
export { ParentInterface } from '@parent_scope/parent_package';
export { ChildInterface } from './main';
我希望我的客户只能依靠我的子包裹,但仍然可以从父包裹中访问我传递的任何东西。
package.json
:
"name": "@client_scope/client_package",
"dependencies": {
"@child_scope/child_package": "1.0.0"
}
main.ts
:
import { ParentInterface, ChildInterface } from '@child_scope/child_package';
const objA: ParentInterface = {};
const objB: ChildInterface = {};