使用 vs.net 的 TypeScript 插件时,如何使一个 TypeScript 文件导入其他 TypeScript 文件中声明的模块?
file 1:
module moo
{
export class foo .....
}
file 2:
//what goes here?
class bar extends moo.foo
{
}
从 TypeScript 1.8 版开始,您可以使用简单的import
就像 ES6 中的语句:
import { ZipCodeValidator } from "./ZipCodeValidator";
let myValidator = new ZipCodeValidator();
https://www.typescriptlang.org/docs/handbook/modules.html https://www.typescriptlang.org/docs/handbook/modules.html
旧答案:从 TypeScript 1.5 版开始,您可以使用tsconfig.json
: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
它完全消除了注释样式引用的需要。
较旧的答案:
您需要引用当前文件顶部的文件。
你可以这样做:
/// <reference path="../typings/jquery.d.ts"/>
/// <reference path="components/someclass.ts"/>
class Foo { }
etc.
这些路径是相对于当前文件的。
你的例子:
/// <reference path="moo.ts"/>
class bar extends moo.foo
{
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)