I'm using:
This is my code:
function plain(){
return (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => {
var originalMethod = descriptor.value; // save a reference to the original method
descriptor.value = function(...args: any[]) {
var result = originalMethod.apply(this, args);
return result.then(function stripRestangularAttributes(response){
return response.plain();
});
};
return descriptor;
};
}
export class XYZ {
@plain
public getSomethingBySomething(data: Data): restangular.IPromise<any> {
if (!entityKey && !period) {
return null;
}
return this.restangularElement.all("route1/route2").post(data);
}
}
I get following error:
error TS1241: Unable to resolve signature of method decorator when called as an expression. Supplied parameters do not match any signature of call target.
It is thrown on the @plain
line.
Some info:
.post(data)
in this example, return promisesI want to:
.plain()
on restangular results, so that I would just use @plain
on any method and all results will get plain()
-ed automagically.@plain
decorator attached: .then(function stripRestangularAttributes(response){
return response.plain();
})
Unfortunately, I can't get what is typescript complaining about in above example.
PS I've been reading this fantastic answer as my TS decorators guide.
Your method decorator shouldn't return a function, according to the spec:
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
Try this instead:
function plain(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) {
var originalMethod = descriptor.value; // save a reference to the original method
descriptor.value = function(...args: any[]) {
var result = originalMethod.apply(this, args);
return result.then(function stripRestangularAttributes(response){
return response.plain();
});
};
return descriptor;
};