According to this article, you can use TypeScript namespaces to import types/interfaces without including an import:
https://scotch.io/tutorials/3-useful-typescript-tips-for-angular
However if I create a namepsace:
export namespace ST {
export interface Ifoo {
}
}
in order to get it recognized, I have to import it like so:
import {ST} from 'suman-types/dts/foo';
export const foo : ST.Ifoo = function () {
};
is there something I am doing wrong? How can I use a namespace to easily import code?
Perhaps this only works with Angular and doesn't really work with CommonJS/Node.js? Not sure why not though.
As is mentioned on the page you refer to this is actually not bound to Angular only.
What I can see on the fist glance is that you use
export
with the namespace itself.The example on scotch.io says you‘re supposed to use export only with the nested interfaces. Like this:
This should do the trick. Then no further
import
should be needed. You‘re supposed to be able to use the namespace throughout the app without any further input statement.