javascript - Typescript, self returning generic -
i'm working on class implements generic interface like:
interface world<t> { get(): t; } class hello implements world< hello > { get(){ return } }
but thinking if class hello
implement world
interface, intead of having use world< anotherclass >
thinking world< world >
can permanent wherever implement world
interface, looks typescript don't accept syntax, there better way so?, maybe there way around it?
i'm sorry it's not clear mean "so can permanent wherever implement world interface". maybe want non-generic interface?
interface world { get(): world; } class hello implements world { get() { return this; } hello() { console.log("hello"); } } class anotherclass implements world { get() { return this; } anotherclass() { console.log("another class"); } } var h = new hello(); var ac = new anotherclass(); var testh = h.get(); //testh implicitly typed hello var testac = ac.get(); //testac implicitly typed anotherclass //these work. var testworld : world; testworld = h.get(); testworld = ac.get();
Comments
Post a Comment