Skip to content
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

Preserve Named Properties when Merging Tuple Types #53930

Closed
5 tasks done
BribeFromTheHive opened this issue Apr 20, 2023 · 4 comments
Closed
5 tasks done

Preserve Named Properties when Merging Tuple Types #53930

BribeFromTheHive opened this issue Apr 20, 2023 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@BribeFromTheHive
Copy link

BribeFromTheHive commented Apr 20, 2023

Suggestion

πŸ” Search Terms

  • Named properties in merged tuple types
  • Rest parameters with named tuple properties
  • Merge tuple types while preserving named properties

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Add the ability to merge tuple types while preserving the named properties of their elements.

πŸ“ƒ Motivating Example

Currently, when tuple types with named properties are merged using the spread operator ..., TypeScript loses the named properties of the tuple elements. This makes it difficult to maintain named parameter hints in function signatures when using rest parameters with merged tuple types.

πŸ’» Use Cases

Consider the following example:

type SimpleArgs = [a: number, b: string];

type MergedArgs = [...SimpleArgs, c: boolean];

function exampleFunction(...args: MergedArgs) {
  const [a, b, c] = args;
  // Do stuff with a,b,c
}

exampleFunction(1, 'hello', true);

In this scenario, the named properties a, b, and c are lost when the tuple types are merged into MergedArgs. As a result, the parameter hints for exampleFunction do not show the named properties when mousing over the function signature.

It would be beneficial to have a way to merge tuple types that preserves the named properties of their elements, improving the developer experience when working with rest parameters in function signatures.

@RyanCavanaugh
Copy link
Member

Currently, when calling the blah function, the editor hints display the args rest parameter, but they do not display the named parameter hints from the tuple type (e.g., a: someType, b: anotherType, etc.).

That's not what I'm seeing?

image

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Apr 20, 2023
@BribeFromTheHive BribeFromTheHive changed the title Improve Editor Hints for Rest Parameters with Tuple Types by Displaying Named Parameter Hints Preserve Named Properties when Merging Tuple Types Apr 20, 2023
@BribeFromTheHive
Copy link
Author

Hi @RyanCavanaugh,

Thanks for getting back to me on this so quickly.

I'd like to apologize that my initial feature request was a bit unclear. After seeing your reply, I realized that what I was trying to achieve was a bit more nuanced than I initially explained. So, I've gone ahead and updated the request with a clearer description/title and some practical use cases.

Thanks for your patience!

  • Luke

@fatcerberus
Copy link

With the updated example in the OP, this looks like a duplicate of #52853

@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed Needs More Info The issue still hasn't been fully clarified labels Apr 20, 2023
@BribeFromTheHive
Copy link
Author

Correct! They are one and the same issue. Thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants