TypeScript、AMD 和引用直接导入 类

TypeScript, AMD and referencing imported classes directly

我用“--module amd”参数调用我的 TSC 编译器。

假设我有一个文件geom.ts,其中包含

export class Cube { //implementation }

如果想引用立方体 class 我会

import geom = require('geom');

var myCuble : geom.Cube;

在 ActionScript 中,我习惯于直接引用导入的 classes - 在 "Cube" 之前不会有 "geom.",除非多个导入和我之间存在冲突需要说明整个包路径。这个 module-dot-class 约定很烦人,有什么我可以做的吗?

从 TypeScript 1.5 开始,您可以使用 ES6 风格的导入语句:

import { Cube } from 'geom';

var myCube: Cube;

通过将代码转换为:

,这将被编译为旧版本的 ECMAScript(如果您不以 ES6 为目标)
var glob_1 = require('glob');
var x = new glob_1.Example();