MichalLytek / MichalLytek/type-graphql
Enable fully typed param decorators
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
It is frustrating that param decorators cannot be fully type checked.
```ts
interface User {
id: string
}
export function CurrentUser() {
return createParamDecorator(({ 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:
```ts
export function CurrentUser() {
return createParamDecorator(({ 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
Contributor guide
Research direction
Start at the createParamDecorator type definition and trace how its generic types flow into a parameter decorator. Compare the current TypeScript declarations with the CurrentUser example, then identify existing decorator tests or examples to extend. Done means an explicit return type such as User is enforced at compile time without breaking existing decorator usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100