Typescript 进口声明的副作用

Typescript 进口声明的副作用,typescript,module,decorator,Typescript,Module,Decorator,从InTypeScript rest开始,我希望通过将HelloService类分离到自己的文件中来实现模块化。下面是: //您好,服务台 从typescriptrest导入{Path,GET,PathParam}; @路径/你好 导出类HelloService{ @路径:名称 @得到 sayHello@PathParam'name'名称:string:string{ 返回Hello+name; } } //索引 从express导入*作为express; 从typescript rest导入{

从InTypeScript rest开始,我希望通过将HelloService类分离到自己的文件中来实现模块化。下面是:

//您好,服务台 从typescriptrest导入{Path,GET,PathParam}; @路径/你好 导出类HelloService{ @路径:名称 @得到 sayHello@PathParam'name'名称:string:string{ 返回Hello+name; } } //索引 从express导入*作为express; 从typescript rest导入{Server}; 导入“./hello service”//这很有效 //下面的方法不起作用 //从“/hello service”导入{HelloService}; //从“./hello service”导入*作为Foo //但它们确实有效,但iif: //新HelloService //新的Foo.HelloService 让app:express.Application=express; Server.buildServicesapp; app.listen3000,函数{ 日志“Rest服务器正在端口3000上侦听!”; }; 简而言之,我期待着3条导入语句:

import './hello-service'
import { HelloService } from './hello-service';
import * as Foo from './hello-service'
在副作用方面是相等的。我最初的解释是,文件被加载和解释,所以@decorators发挥了他们的魔力,我不知道他们是如何工作的,但显然不是

有人能指出这些说法之间的区别并解释不同的结果吗? 这是医生的电话号码


编辑:我知道也可以使用这个库,但这不是我感兴趣的地方。

解释来自

这是在transpiler级别进行的优化的一部分,检查是否使用了来自给定导入的任何导出,它将从最终的捆绑包中被打包