Skip to content
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

Enable fully typed param decorators #1286

Open
mull opened this issue May 24, 2022 · 0 comments
Open

Enable fully typed param decorators #1286

mull opened this issue May 24, 2022 · 0 comments
Labels
Community 👨‍👧 Something initiated by a community Discussion 💬 Brainstorm about the idea Enhancement 🆕 New feature or request

Comments

@mull
Copy link

mull commented May 24, 2022

Is your feature request related to a problem? Please describe.
It is frustrating that param decorators cannot be fully type checked.

interface User {
  id: string
}

export function CurrentUser() {
  return createParamDecorator<MyContext>(({ context }) => {
    return "I can return whatever I want here"
  })
}

class SomeResolver {
  @Mutation(() => MyType)
  createSomething(
    @CurrentUser() user: User // @CurrentUser() is implicitly `any` type
  ) {
    // ...
  }
}

Describe the solution you'd like
It may be that TypeScript itself is preventing this from happening, but I think this would be a great addition:

export function CurrentUser() {
  return createParamDecorator<MyContext, User>(({ context }) => {
    return "I can no longer return this" // This would fail
  })
}

It seems like the ParameterDecorator type from TS itself may prevent this from happening (I'm brand new to TS metadata)?

Describe alternatives you've considered
Can't think of any alternatives, happy to hear them!

Additional context
I can provide a PR with implementation, tests, and examples, but need a nudge in the right direction.

  • Typescript 4.6
  • type-graphql 1.1.x
  • reflect-metadata ^0.1.13
@MichalLytek MichalLytek added Enhancement 🆕 New feature or request Community 👨‍👧 Something initiated by a community Discussion 💬 Brainstorm about the idea labels May 24, 2022
@MichalLytek MichalLytek added this to the Future release milestone May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Discussion 💬 Brainstorm about the idea Enhancement 🆕 New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
@mull @MichalLytek and others