Display signature help or completions for tuples with labels
#53,197 创建于 2023年3月10日
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
Suggestion
🔍 Search Terms
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
✅ 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
📃 Motivating Example
declare const coords: [x: number, y: number]
const [/**/] = coords
The problem: having no idea what a name to type as you don't know what the type of it.
I'm using it with my plugin and it looks very simple (and useful IMO):
Of course, you can hover of the variable to fiture it out, but what about the following example:
const a: {
coords: [x: number, y: number] | string | { x: number; y: number }/* | even more types */
} = {
coords: [/**/], // the type with x, y tuples can be even truncated, so you can only guess names of labels
}
I understand that labeled tuples introduced in ts4.0 were designed primarily for parameters usage, but I've seen them used for shorter static data declarations as well.
However, if you think that usage signature help is redundant and incorrect, what about having completions for tuple labels at least? There is already completions when acessing such symbols via dot property access. For example for first example it would be keyword completion with label x and [0]: number detail.