microsoft / microsoft/TypeScript

Allow mapped tuples to have behaviour based on index

Open
#29,920 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Search Terms

mapped tuples index

Suggestion

I want to be able to create a tuple from function parameters and have all elements in the tuple optional other than the firstK

Use Cases

I am trying to create a curry implementation that allows you to curry any number of parameters. The first parameter must be specified but all other params are optional.
Would be good to be able to remove the last param as well.

Examples

something along the lines of

type OptionalExceptFirst<T> = {
    [K in keyof T]:isFirst ? ? T[K] : T[K];
};
type AllExceptLast<T> = {
    [K in keyof T]:isLast ? never : T[K];
};

The syntax will need some work hopefully the intended functionality is clear.

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, etc.)
  • [ x] This feature would agree with the rest of TypeScript's Design Goals.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points, so first review how mapped tuples currently behave and how TypeScript represents tuple positions. Clarify the intended rules for optionality based on the first and last indexes before proposing implementation and tests; done would require an agreed design plus validated compiler behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.