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
Right now while using decorators the javascript seems to work, but the types are too strict.
As you can see here the following does not compile:
declarevar_: any;exportfunctionThrottle(milli: number){interfaceThrottledextendsFunction{now: Function}returnfunction<TextendsThrottled>(target: Object,propertyKey: string,descriptor: TypedPropertyDescriptor<Function>): TypedPropertyDescriptor<T>{letoriginalMethod=descriptor.value;// NOTE: Do not use arrow syntax here. Use a function expression in// order to use the correct value of `this` in this methoddescriptor.value=<any>_.throttle(function(){originalMethod.apply(this,arguments);},milli);(<Throttled>descriptor.value).now=<any>function(){originalMethod.apply(this,arguments);};return<TypedPropertyDescriptor<T>>descriptor;}}classCtrl{constructor(scope: any){scope.$watch("foo",this.throttledByClassWatch);this.throttledByClassWatch.now()//unrecommended now call}
@Throttle(100000)privatethrottledByClassWatch(){}}
I might have the types a little wrong but I have tried many other permutations. It seems to be because the expected type is declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void; and so the input T must match the output T.
Ideally the now could also inherit the generic type T so it could be type checked.
The text was updated successfully, but these errors were encountered:
looks like a duplicate of #4881. you might find my comment in #5627 (comment) helpful as a work around ins some cases, though would not work in your sample.
Right now while using decorators the javascript seems to work, but the types are too strict.
As you can see here the following does not compile:
I might have the types a little wrong but I have tried many other permutations. It seems to be because the expected type is
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
and so the input T must match the output T.Ideally the
now
could also inherit the generic typeT
so it could be type checked.The text was updated successfully, but these errors were encountered: