-
-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typed decorators - enhanced type-safety #221
Comments
@19majkel94 export interface ClassType extends Function {
new (...args: any[]): unknown;
}
export type StaticMethodParameterDecorator = (
<
TMethodName extends string | symbol,
TClassType extends ClassType & Record<TMethodName, (this: TClassType, ...args: unknown[]) => unknown>
>
(
targetClass: TClassType,
methodName: TMethodName,
parameterIndex: number
) => void
);
function staticParameterDecorator(): StaticMethodParameterDecorator {
return () => {};
}
class Cl {
method( // instance method, but no error
@staticParameterDecorator()
bool: boolean
) {
return bool;
}
} Did you find a solution? |
Static method? Does TypeGraphQL supports this? 😜 You can check out the |
@19majkel94 Well, ok, we can skip this part, as there are no decorators targeted to static accessors/properties/methods in |
I think that typed decorators will be superseded by TypeScript transform plugin to enhance reflection system - more info soon 💪 |
Hello @MichalLytek. |
Right now it's dangerously easy to have inconsistence between schema type and TS type in class definition:
It can be easily fixed (I was not aware of this possibility in TS) by using generics instead of predefined types like
PropertyDecorator
.Quick demonstration of the proof of concept:
TODO: figure out how to get rid of false negative, like using custom scalars, etc.
Disclaimer: Inspired by @stephentuso ts-graphql 😃
The text was updated successfully, but these errors were encountered: