-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Infer method name for parameter decorator #30102
Comments
Hi everyone, Can I do anything to quicken this thread ? I've discussed the same day with @dragomirtitian on Gitter and we are will to PR to patch this. Thanks. |
Just as an experiment I made the changes we (me an @SalathielGenese) think are required, you can see them here These changes do the following:
Uses cases enabled:
type FilterKeysByMethodArg<T, TIndex extends number, TParam> = {
[P in keyof T] : T[P] extends (...p: infer A) => any ?
A extends Record<TIndex, TParam> ? P: never: never
}[keyof T]
declare function TypedParameter<TParam>():
{
<T extends Record<TName, (...p: any[]) => any>, TIndex extends number, TName extends FilterKeysByMethodArg<T, TIndex, TParam>>(t: T, m: TName, pIndex: TIndex): void
}
class Play
{
public method (
@TypedParameter<string>() o: number, // err
@TypedParameter<number>() test: number // ok
): void
{
throw new Error('Not yet implemented');
}
} Problems:
|
Thanks @dragomirtitian . I hope we'll hear from them, now that a PR illustrates the issue we're trying to solve. Maybe the label Needs Investigation will be less appropriate ? Anyhow, much thanks !!! |
Stumbled with such a problem recently. I think it is definitely not that hard to fix it. Let's make TypeScript strongly typed again! |
Hi any movement on this? Now that the 3.4 release rush is over can I submit a PR with the code I have for this (@DanielRosenwasser , @RyanCavanaugh, @rbuckton) ? |
We would love to see this opened up for @dragomirtitian’s PR so that we could take advantage of it in function postSomething( @Body<Thing1>() aParameterWhosTypeIsNotInferred: Thing2 ): Thing2 |
@dgreene1 Just speculating, but probably since decorators are such a mess (with regard to spec compatibility, since the proposal changed) in TS right now you will not see any changes to decorators any time soon. The current decorator proposal is still stage 2 and actually does not include parameter decorators which will be in a future version. |
TypeScript Version: 3.3.3
Tried with @next (3.4.0-dev.201xxxxx) ? NO
Search Terms: type:issues infer method name parameter decorator
Code
Expected behavior:
@Parameter()
should error just as@Method()
when applied toanother_method()
because them
parameter is typed"method"
(which should reduced the set of method). i.e method name should be enforced.Actual behavior: No error
Playground Link: https://typescript-play.js.org
Use case :
I crafted a type that filters method names with the
nth
parameters iff that parameters is of the given typeT
.See
KeysToTypedNthParameter
definition hereLater, I used that type to infer method name for my parameter decorator -
@Inject
- in the excerpt below, I marked the ONLY line that should error and why (but both lines actually error)Here is
@Inject
decorator definition and complete code -The text was updated successfully, but these errors were encountered: