typescript-class

Initializing generic type inside generic class in Typescript

对着背影说爱祢 提交于 2020-01-06 08:09:09
问题 I want to initialize a generic class variable inside a generic class using a generic type, but I can't figure out if there is a way to do this. Initializing with types works fine, it doesn't seem like it work with generics though. type EventCallback<I, O> = (event: I) => O; type ListenerList<K extends string | symbol | number, I, O, V extends EventCallback<I, O>> = { [T in K]: V[]; }; const test: ListenerList<string, string, string, (event: any) => any> = {}; // Works fine export default

Extending type when extending an ES6 class with a TypeScript decorator

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 05:22:47
问题 I am trying to decorate a class with a decorator ( a-la-angular style), and add methods and properties to it. this is my example decorated class: @decorator class Person{ } and this is the decorator: const decorator = (target)=>{ return class New_Class extends target { myProp:string } } but myProp is not a known property of Person: person.myProp //Error - myProp does not exist on type Person How can I decorate a typescript class and preserve type completion, type safety, etc ? 回答1: To