One issue missing with parameter decorators in general and for types is the ability to get parameters information and types.
class A {
f(x:uint32, ...y:uint32, z?:():void):string {
}
}
Now, one could stringify and parse out parameters, but with decorators and such that would be brittle/insane. So a reflection would be expected for functions. I'd expect something similar to a property descriptors object except they're ordered, so an array.
Function.reflect(A.prototype.f);
The returned value would be an array in order to handle overloaded functions:
I could use this to build say a REST routing system connecting up basic type validation.
Would connecting metadata to this structure be intuitive? I think it would, but I'm not sure how well it would scale with interface types which also have decorators and such. Should work I believe.
const VALIDATIONS = Symbol();
function validate(validator) {
return (value, context) => {
if (kind === 'parameter') {
let validations = context.getMetadata(VALIDATIONS) ?? [];
validations.push(validator);
context.setMetadata(VALIDATIONS, validations);
return function(v:uint32):uint32 {
return v;
};
}
};
}
function f(
@validate(x => x > 5)
x:uint32
):void {
}
Function.reflect(f);
One issue missing with parameter decorators in general and for types is the ability to get parameters information and types.
Now, one could stringify and parse out parameters, but with decorators and such that would be brittle/insane. So a reflection would be expected for functions. I'd expect something similar to a property descriptors object except they're ordered, so an array.
The returned value would be an array in order to handle overloaded functions:
I could use this to build say a REST routing system connecting up basic type validation.
Would connecting metadata to this structure be intuitive? I think it would, but I'm not sure how well it would scale with interface types which also have decorators and such. Should work I believe.