简体   繁体   English

如何从 typescript 文件默认导出所有功能?

[英]How to export all functions from typescript file with default?

Common example of this export type is React.这种导出类型的常见示例是 React。 We can use this: import React, {Component} from "react" .我们可以使用这个: import React, {Component} from "react" And then we can use both React.Component and Component.然后我们可以同时使用 React.Component 和 Component。 How to achieve this?如何做到这一点?

  1. Ensure you have module CommonJS in tsconfig.json确保您在tsconfig.json中有模块CommonJS
  2. wrap all functions in module and add export keyword to all you want to export将所有功能包装在模块中,并将 export 关键字添加到您要导出的所有功能中
  3. Add export = <YOUR MODULE NAME> to the end of your fileexport = <YOUR MODULE NAME>添加到文件末尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM