Closed
Description
I think this is useful syntax :)
sample.
interface IFoo {
foo: string; // not optional
}
class Bar implements IFoo? {
// Bar does not have a foo property.
}
new Bar().foo;
How useful.
class Foo implements Lib.IListener? {
constructor() { Lib.injectInto(this); }
}
module Lib {
export interface IListener {
on(data: any): void;
}
export function injectInto(target: any) {
target.on = () => { /* do something... */ };
}
export function listen(receiver: IListener) {
receiver.on("foobar");
}
}
var obj = new Foo();
Lib.listen(obj);
Lib.listen({
on: ()=> {} // on method required
});
In real world.
case 2.
// Emissary#emitter
https://github.com/atom/emissary#emitter
// .d.ts
https://github.com/borisyankov/DefinitelyTyped/blob/b4aba562ef4192bc3f2e770ab2018f89e047836b/emissary/emissary.d.ts#L13
// usage in TypeScript (dirty hack!)
https://github.com/vvakame/language-review/blob/d23f8797bbb6e99d636399a14c7035c4809ab365/lib/util/emissary-helper.ts#L11