You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a decoator which is typed like so to add a static method to a decorated class. I would like the decorator's typing information to be evaluated and added to the class' typing information.
Decorator typing information (Biscuit is the name of my engine, don't judge I'm not good at naming things):
typeConstructArgs<T>=Textends(new(...args: infer C)=>any)?C: never;typePrototype<T>=(Function&{prototype: T});//First set of params are the ones supplied in the decorator, like: @BiscuitObject(common);declarefunctionBiscuitObject<SerialiseTypeextendsObject>(datatype: SerialiseType): (//Second set of params are the class the decorator is decorating, in this case the BiscuitObject.<BiscuitClassextendsFunction&{prototype: Object},BiscuitextendsPrototype<BiscuitClass>,ConstructorArgumentsextendsConstructArgs<Biscuit>,>(biscuit: BiscuitClass)=>BiscuitClass&{//We return a deserialise function that takes some data and converts it// into a new object of this class type.deserialise: (object: SerialiseType, ...args: ConstructorArguments)=>Biscuit;});
Example code:
classBDataType{tell!: string;constructor(tell: string){this.tell=tell;}}
@BiscuitObject(BDataType)classB{tell: string;param: string;constructor(param: string){this.param=param;this.tell="hi";}serialise(){returnnewBDataType(this.tell);}method(){console.log(this.tell,this.param);}}B.deserialise(newBDataType("world"),"hello").method();//This line errors currently.
The TypeScript team also has said on several occasions that they will not expand on the experimental decorator support until TC39 standardized the decorator support.
We're not expanding the current experimental decorator implementation any further since this is something we're trying to standardize through the TC39 proposal. Suggestions for more behavior there should be taken to the tc39 proposal repo
Search Terms
Class, decorators, typing.
Suggestion
I have a decoator which is typed like so to add a static method to a decorated class. I would like the decorator's typing information to be evaluated and added to the class' typing information.
Decorator typing information (Biscuit is the name of my engine, don't judge I'm not good at naming things):
Example code:
https://www.typescriptlang.org/play?#
Use Cases
I want to use this to automate the addition of several common static functions that I use across about 20 different classes in my codebase.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: