microsoft / microsoft/TypeScript
Make ParameterDecorator and the like generic
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
lib Update Request
Missing / Incorrect Definition
ParameterDecorator is currently not generic, it can be attachted to any parameter. However, when a decorator is used for e.g. Dependency Injection purposes, some decorators require the type of the parameter to be consistent with the type of the decorator
Sample Code
E.g. we want this to work
class MyController {
requestThings(@UserId() userId: number): Thing[] { return [] }
}
But this to fail:
class MyController {
requestThings(@UserId() userId: string): Thing[] { return [] }
}
(as userId will be a number, not a string so the injection should ideally not be possible (at compile time)
Currently UserId is done more or less this way:
const UserId = (): ParameterDecorator => (target, key, index) => {
// do stuff
}
while I'd like to add number to ParameterDecorator:
const UserId = (): ParameterDecorator<number> => (target, key, index) => {
// do stuff
}
and I'd like typescript to check this when applying a decorator.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the ParameterDecorator definition and the compiler checks for applying parameter decorators. Compare the issue's number and string examples to the current behavior, then determine how generic parameter types should be represented and validated. Done means valid decorator applications are accepted and mismatched parameter types are rejected with appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100