dsherret / dsherret/ts-morph

Read tuple element labels

Open
#1,255 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Is your feature request related to a problem? Please describe.**

For documentation purposes I would like to get access to the [tuple element labels](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#labeled-tuple-elements), if any. Example:

```ts
const a: (() => [someLabel:1]) = [1]
```

**Describe the solution you'd like**

The function `t.getTupleElements()` could return more structured data. It currently just returns a `Type`. How about this:

```ts
interface TupleElementInfo {
label: null | string
type: Type
}
```

**Describe alternatives you've considered**

Given the current API maybe this would be consistent:

```ts
t.getTupleElementLabel()
```

But I find that weird since there's no guarantee that `t` is a tuple there...

Contributor guide

Open the contributing guide

Research direction

Read CONTRIBUTING.md, then inspect the existing t.getTupleElements() API and how its Type result is consumed. Compare the proposed structured TupleElementInfo shape with the alternative label method using the labeled-tuple example. Done means tuple element labels, when present, are exposed consistently without breaking existing tuple type access.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.