建议
🔍 搜索词
元组, 标签, 参数, 解构
✅ 可实现性检查清单
我的建议满足以下准则:
- [x] 这不会对现有的TypeScript/JavaScript代码造成破坏性的更改
- [ x] 这不会改变现有JavaScript代码的运行时行为
- [ x] 这可以在不根据表达式的类型发出不同的JS的情况下实现
- [x] 这不是一个运行时特性(例如库功能,具有JavaScript输出的非ECMAScript语法,JS的新语法糖等)
- [ x] 这个特性会与TypeScript's Design Goals的其他部分一致。
⭐ 建议
当使用元组类型捕获函数参数时,如果任何参数被解构,则会丢失参数名称,这会导致在尝试确定原始类型参数顺序时出现不太理想的情况。
📃 动机示例
// 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.
*/
1条答案
按热度按时间wko9yo5t1#
元组标签是一种尽最大努力的保留;如果我们得到一个不是超级复杂的修复,我们会考虑它,但我们不希望采取任何会增加大量代码的东西。