Allow skipping some generics when calling a function with multiple generics
Right now in TypeScript it's all or nothing when calling generic methods. You can either skip typing all the generics altogether and they will be inferred from the context (if possible), or you have to manually (re)define all of them. But the reality isn't black and white, there are also shades of gray, where we can infer types for some of the generic parameters, but not others. Currently those have to be unnecessarily verbose by forcing the programmer to explicitly restate them. Take a look at these 3 cases: Case 1 - everything can be inferred - no need to call the method with `<>` definition: ``` ts function case1<A, B, C>(a: A, b: B, c: C): A {} example(1, '2', true); ``` Compiler knows that: A is number B is string C is boolean --- Case 2 - nothing can be inferred, so we need to state what A, B and C should be, otherwise they'll default to `{}`: ``` ts function case2<A, B, C>(): A {} example<number, string, boolean>(); ``` --- Case 3 - the one that's interesting to this feature request - some can be inferred, some can't: ``` ts function case3<A, B, C>(b: string, c: boolean): A {} // incorrect type of A - left unspecified: example('thing'); // correct, but unnecessarily verbose - we already know that 'thing' is a string and true is a bool example<number, string, boolean>('thing', true); ``` Now, typing `string, boolean` in the above example isn't a big deal, but with complex scenarios, say with a method using 5 generics, where you can infer 4 of them, re
Posted by niieani on Aug 26, 2016, 11:13 PM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
Allow skipping some generics when calling a function with multiple generics
Right now in TypeScript it's all or nothing when calling generic methods. You can either skip typing all the generics altogether and they will be inferred from the context (if possible), or you have to manually (re)define all of them. But the reality isn't black and white, there are also shades of gray, where we can infer types for some of the generic parameters, but not others. Currently those have to be unnecessarily verbose by forcing the programmer to explicitly restate them. Take a look at these 3 cases: Case 1 - everything can be inferred - no need to call the method with `<>` definition: ``` ts function case1<A, B, C>(a: A, b: B, c: C): A {} example(1, '2', true); ``` Compiler knows that: A is number B is string C is boolean --- Case 2 - nothing can be inferred, so we need to state what A, B and C should be, otherwise they'll default to `{}`: ``` ts function case2<A, B, C>(): A {} example<number, string, boolean>(); ``` --- Case 3 - the one that's interesting to this feature request - some can be inferred, some can't: ``` ts function case3<A, B, C>(b: string, c: boolean): A {} // incorrect type of A - left unspecified: example('thing'); // correct, but unnecessarily verbose - we already know that 'thing' is a string and true is a bool example<number, string, boolean>('thing', true); ``` Now, typing `string, boolean` in the above example isn't a big deal, but with complex scenarios, say with a method using 5 generics, where you can infer 4 of them, re
Comments (0)
No comments yet. Start the discussion.