我的问题与此问题几乎相同: https://github.com/Microsoft/TypeScript/issues/4529
说我有这个:
//exported imports
export {ISumanOpts, IGlobalSumanObj} from 'suman-types/dts/global';
export {ITestCaseParam} from 'suman-types/dts/test-suite';
export {IHookParam} from 'suman-types/dts/test-suite';
export {IDescribeFn} from 'suman-types/dts/describe';
export {ItFn, ITestDataObj} from 'suman-types/dts/it';
export {IBeforeFn} from 'suman-types/dts/before';
export {IBeforeEachFn} from 'suman-types/dts/before-each';
export {IAfterFn} from 'suman-types/dts/after';
export {IAfterEachFn} from 'suman-types/dts/after-each';
export {DefineObjectContext as IDefObjCtx} from "./test-suite-helpers/define-options-classes";
export {DefineObjectTestCase as IDefObjTestCase} from "./test-suite-helpers/define-options-classes";
export {DefineObjectAllHook as IDefObjAllHook} from "./test-suite-helpers/define-options-classes";
export {DefineObjectEachHook as IDefObjEachHook} from "./test-suite-helpers/define-options-classes";
export namespace s {
// ! I want to move all of the above exported items into a namespace here
}
有没有办法使用namespace
或module
将内容导出为命名空间的一部分而不是单独导出它们?
我已经接近了这个:
所以我尝试将它们更改为导入,然后将它们放在const上,如下所示:
但正如您所看到的,我的一些声明是接口,而不是类,在这种情况下看起来像我得到错误消息“仅指一个类型,但在这里被用作值”。
答案 0 :(得分:2)
这是我的工作:
import * as Block from './block'
import * as FullNode from './full-node'
import * as ListOnChain from './list-on-chain'
import * as HashTools from './hash-tools'
import * as KeyValueStorage from './key-value-storage'
import * as SequenceStorage from './sequence-storage'
import * as SmartContract from './smart-contract'
import * as NodeBrowser from './node-browser'
import * as NetworkApi from './network-api'
import * as NetworkClientBrowserImpl from './network-client-browser-impl'
import * as NodeApi from './node-api'
import * as NodeImpl from './node-impl'
import * as NodeTransfer from './node-transfer'
import * as NodeNetworkClient from './node-network-client'
import * as WebsocketConnector from './websocket-connector'
export {
Block,
FullNode,
ListOnChain,
HashTools,
KeyValueStorage,
SequenceStorage,
SmartContract,
NodeBrowser,
NetworkApi,
NetworkClientBrowserImpl,
NodeApi,
NodeImpl,
NodeTransfer,
NodeNetworkClient,
WebsocketConnector
}
然后在另一个文件中,我可以这样导入,所有文件都将保留在自己的空间中:
import * as AllComponents from 'blockchain-js-core'
如果要一个一个地导入它们,可以执行以下操作:
import {
Block,
FullNode,
ListOnChain,
HashTools,
KeyValueStorage,
SequenceStorage,
SmartContract,
NodeBrowser,
NetworkApi,
NetworkClientBrowserImpl,
NodeApi,
NodeImpl,
NodeTransfer,
NodeNetworkClient,
WebsocketConnector
} from 'blockchain-js-core'
可以在此处找到示例:https://github.com/ltearno/blockchain-js/blob/master/blockchain-js-core/src/index.ts