[英]export typescript classes and interfaces from a single file
I want to be able to export some of my classes/interfaces/enums from other files in a single file. 我希望能够将其他文件中的某些类/接口/枚举导出到一个文件中。 This is how I have done it in javascript:
这就是我在javascript中完成的方式:
module.exports = {
Something = require("./src/something").default,
SomethingElse = require("./src/something-else").default
}
I've noticed that I do not get intellisense from my webstorm (jetbrains) editor, and I'm pretty sure that there is an easier way to implement this in typescript. 我注意到我没有从webstorm(jetbrains)编辑器中获得智能感知,并且我很确定有一种更容易的方法来在打字稿中实现这一点。 I've heard and read about modules but I still don't get what they purpose is, most likely they could help me here.
我听说过有关模块的内容,但我仍然不明白它们的用途,很可能它们可以在这里为我提供帮助。
I want to be able to use this style on the library consumer: 我希望能够在库使用者上使用此样式:
import { Something, SomethingElse } from "my-ts-library";
...
Any ideas? 有任何想法吗?
You can flow my example: 您可以举我的例子:
Something.ts
export default (a: number, b: number): number => {
return a + b;
};
SomethingElse.ts
export default (a: number, b: number): number => {
return a - b;
};
my-ts-library.ts
import add from './src/Something.ts';
import sub from './src/SomethingElse.ts';
export {
add,
sub,
};
using your lib 使用你的lib
import { add, sub } from "my-ts-library";
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.