Microsoft/TypeScript

Transforms on functions that have destructured arguments lose parameter names

Open

#46.493 aberto em 23 de out. de 2021

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)TypeScript (6.726 forks)batch import
Effort: ModerateExperience EnhancementHelp Wanted

Métricas do repositório

Stars
 (48.455 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)

Description

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.
*/

💻 Use Cases

Guia do colaborador