Microsoft/TypeScript
在 GitHub 查看Transforms on functions that have destructured arguments lose parameter names
Open
#46,493 创建于 2021年10月23日
Effort: ModerateExperience EnhancementHelp Wanted
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
Suggestion
🔍 Search Terms
tuple, labels, parameters, destructure
✅ Viability Checklist
My suggestion meets these guidelines:
- [x ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [ x] This wouldn't change the runtime behavior of existing JavaScript code
- [ x] This could be implemented without emitting different JS based on the types of the expressions
- [x ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [ x] This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
When using tuple types to capture function arguments the argument names are lost if any of the arguments are destructured, this leads to a less than ideal situation when trying to determine argument order of primitive types.
📃 Motivating Example
// trivial exampled
const transform = <T, U extends unknown[]>(
factory: (...args: U) => T
) : ((...args: U) => T) => factory
const transformed = transform(({ test } : { test: string }, b: string) : string => `${test}:`${b}`)
/*
The intellisense for the transformed function shows args_0, args_1, the first
argument clearly has no name, however the second does but is still not shown. If
all arguments are named then everything works as expected. I realize this
is a fairly trivial example, however, it would significantly improve usage of
transformed functions, particularly if those function have multiple primitive
arguments whose order could be confused without names.
Additionally I understand the potential for argument name collision, e.g.
if argument two was for some reason called args_0, however, I believe this
case is unlikely and also could be fixed with a numeric suffix which would
still retain the intent.
*/