microsoft / microsoft/TypeScript

Order member intellisense by inheritance

オープン
#37,362 コメント 3 件 リアクション 15 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Suggestion

I would like to see an optional way to allow the members of an object be displayed in the order in which they are inherited. In other words, the members should be listed from most specific to most general. Subclasses before superclasses. Perhaps a user could have this be their default intellisense behavior, or there could be a key-press to toggle this behavior.

Use Cases

In several systems I've either worked in or looked at, I found myself thinking that it would be beneficial to order members by their order of inheritance. Consider this case: You have a Node in TypeScript or ESLint, and you narrow it to a certain kind of Node, for example, a CallExpression. You narrowed it to a CallExpression type because you want to do something specific to the Node only if it is the CallExpression type. You probably want to call a certain method or access a certain member which did not exist on Node but exists on CallExpression. As far as I'm concerned, the most important members in any particular object are the ones most recently inherited. If I only needed the information from Node, I would not have needed to narrow the type. Hence, I would like to see members from subclasses prioritized over members from superclasses.

Often times when working in a system where objects have tons of methods and properties, I find myself putting the ts.CallExpression type somewhere so I can go-to-definition and look for myself what the "latest" methods are for a narrowed object. Here's a little reenactment of what I've actually done during development many times:

intellisense video

This example actually uses ts-node, which, as a side effect of being a wrapper for TS, wraps properties as methods. E.g. returnType: Type becomes getReturnType(): Type in ts-node. It also aggregates all useful operations you could perform on/with an object, e.g. it allows you to do things like call getType() directly on any Node, which under the hood delegates to the proper TS typechecker API.

Examples

How it could look:

image

In the above image, B.y comes before A.x because B is the lowest subclass and A is the superclass.

Members inherited from the same class or same type would be sorted alphabetically.

It is possible for a particular type to inherit members from multiple types along the same inheritance level via intersection types. In this case, members of each individual type would be grouped together, with subsequent intersected types taking priority. E.g. A & B would display all the members of B as a group, followed by all the members of A as a group.

image

Groups could optionally be separated by extra spacing or perhaps a horizontal bar:

image

Keep in mind that types which have been reconstructed out of intersected types would not be affected:

image

Members from subclasses or subsequent types in an intersection which intersect with superclasses or prior types in an intersection should be listed with the superclass or prior type group.

image

There could also optionally be a keybind for VSCode which toggles this setting, so you could switch between alphabetical and inheritance-based ordering on the fly.

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Issue にはファイル、テスト、エントリーポイントが記載されていません。まず継承と交差の例、およびグループ内をアルファベット順にするという要求された挙動を確認してください。完了には、オプションのメンバーの順序と任意の toggle について、実装および検証の方針に合意する必要があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。