Reputation: 100000
I have this TypeScript code:
import * as suman from 'suman';
const Test = suman.init(module,{
ioc: {
a: 'foo',
b: 'far'
} as suman.Ioc
});
As you can see I am trying to declare that the ioc object has a type of suman.Ioc (ioc object should "adhere to the Ioc interface"). But my IDE says "cannot find namespace 'suman'".
How can I create a type and reference it in my code in this scenario? I'd like to be able to reference the Ioc object type from the suman import if possible.
In other words, I don't want to do this all in the same file:
declare namespace suman {
interface Ioc {
a: string,
b: string
}
}
import * as suman from 'suman';
const Test = suman.init(module,{
ioc: {
a: 'foo',
b: 'far'
} as suman.Ioc
});
the reason is because I would then have to repeat the namespace declaration for every file like this which shouldn't be necessary (or advised).
Upvotes: 0
Views: 74
Reputation: 15589
suman
is typed but the typed version is not release yet.
For now, you can installing it by npm install sumanjs/suman
if you are comfortable to use the latest code.
If you want to use the latest release AND use the typings, you can consider using typings
to install the typings file: typings install suman=github:sumanjs/suman/lib/index.d.ts
and include typings/index.d.ts
in your tsconfig.json
.
As for as suman.Ioc
, it is a way to tell the compiler that "hey, I know that you think this 'thing' is of some other type, but I would like you to treat it as 'suman.Ioc'".
That's why, even if the typings is there, it will not do what you wanted.
Luckily, the typings supplied by suman
will be working fine for you.
Upvotes: 1