Example of a typescript definition file using the decomposed class pattern:
declare module io {
interface IOStatic {
new(name: string): IOInstance;
name: string;
}
interface IOInstance {
get(): string
}
}
declare var IO: io.IOStatic;
declare module "IO" {
export = IO;
}
It is used in:
/// <reference path='external.d.ts' />
import IO = require('IO');
var x = new IO('John');
which works fine.
Question: how can I used the type definition of the IO instance in a type check, e.g.:
getName(io: IO): string {
return io.get();
}
error TS4022: Type reference cannot refer to container 'IO'. Should I export the instance definition too? If yes, how?