build - Typescript export syntax & code structuring -
i'm building typescript library, , following way:
- one
class(interface) / file in dev sources - since whole library "belongs together", can go under 1 namespace
- when building, want able create single output
js,d.tsfile, relevant exports/definitions.
the way tried following:
i used /// <reference path="..." /> syntax, reference other files
foo.ts
class foo { // stuff } bar.ts
/// <reference path="foo" /> class bar extends foo { // example referencing compilation unit } create tsconfig.json file, uses out option, concatenated single file:
{ "compileroptions": { "module": "commonjs", "target": "es5", "out": "src-gen/app.js" /* other options ... */ } } and add single file, exports stuff, want able import other files, this:
exports.ts
/// <reference path="bar" /> export {bar} // don't want expose foo, since not relevant users of lib. but export {bar} line gives following compile error:
circular definition of import alias 'bar'. import bar
i have no idea, error means, since bar not imported anywhere, referenced using /// <reference> syntax.
my whole goal @ end is, have single file, js file output, looks this:
/* compiled js source of foo */ /* compiled js source of bar */ exports = { bar } my question(s) are:
- is valid way things?
- if yes, what's problem
export {bar} - if no, how achieve, want do?
thanks in advance, help/advice!
i think want use modules:
foo.js
module mymodule { class foo { // stuff } } bar.js
module mymodule { export class bar extends foo { // stuff } } then don't need exports.js, since items marked export exported.
i believe that, if compile files @ once, won't need /// <reference lines, either.
edit: think answer question here: creating single commonjs module several typescript classes
Comments
Post a Comment