typescript - Reference .ts file for type check only -
i'd reference .ts file in .ts file. in real project, need type safety (overriding inherited member correct compilation).
my sample:
test1.ts:
export class test1 { }
test2.ts:
/// <reference path="test1.ts" /> export class test2 { abc: test1; // error: test1 not found }
is not possible? i'd avoid importing overhead don't need in outputted javascript file.
update: use test1 amd module class test1 instanciated , injected instance of class test2 underlying framework. why need export keyword don't want directly import module type1 - need reference class avoid compiler errors , have type safety etc..
without using module loader
the export keyword @ root level of file relevant if using module pattern (amd / commonjs). if not following work:
test1.ts:
class test1 { // not use export }
test2.ts:
/// <reference path="test1.ts" /> class test2 { abc: test1; // no error }
however if responsible ensuring test1.js loaded before test2.js, using script tag.
note: if use root level export without using module loader e.g.:
export class test2 { }
the generated javascript:
var test2 = (function () { function test2() { } return test2; })(); exports.test2 = test2;
is wrong since exports not defined anywhere.
if are using amd (or commonjs):
then need use import tell loader load file:
test1.ts:
export class test1 { }
test2.ts:
// no reference other ts required. import mod = module("test1"); // instead need load module export class test2 { abc: mod.test1; // reference module }
additionally
in amd land each file is module. prefer not have module inside file since level of redirect. i.e. need importedfile.module.class
instead of importedfile.class
importedfile
chose call file on import ( called mod
in given example )
Comments
Post a Comment