I'm building a typescript library, and I would like to do it the following way:
- One
class
(interface
) / file in the dev sources - Since the whole library "belongs together", all can go under 1 namespace
- When building, I want to be able to create a single output
js
andd.ts
file, only with the relevant exports/definitions.
The way I tried to do is the following:
I used the /// <reference path="..." />
syntax, to reference other files
Foo.ts
class Foo {
// stuff
}
Bar.ts
/// <reference path="Foo" />
class Bar extends Foo {
// just an example for referencing another compilation unit
}
Create a tsconfig.json
file, which uses the out
option, so everything is concatenated into a single file:
{
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"out": "src-gen/app.js"
/* other options ... */
}
}
And finally add a single file, which exports all the stuff, what I want to be able to import from other files, like this:
Exports.ts
/// <reference path="Bar" />
export {Bar} // don't want to expose Foo, since its not relevant for users of the lib.
But the export {Bar}
line gives the following compile error:
Circular definition of import alias 'Bar'. import Bar
I have no idea, what this error means, since Bar
is not imported anywhere, only referenced using the /// <reference>
syntax.
My whole goal at the end is, to have a single file, js
file as output, which looks like this:
/* compiled js source of Foo */
/* compiled js source of Bar */
exports = {
Bar
}
My question(s) are:
- Is this a valid way to do things?
- If yes, what's the problem with
export {Bar}
- If no, how would you achieve, what I want to do?
Thanks in advance, for any help/advice!