microsoft / microsoft/TypeScript

Improve quick info on JSX component elements

オープン
#45,140 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

説明

TS Template added by @mjbvz

TypeScript Version: 4.4.0-dev.20210713

Search Terms

  • react
  • prop-types
  • jsx

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.58.2 (was happening before this version as well)
  • OS Version: Mac OS 10.14

Steps to Reproduce:

  1. Create a React functional component like this:
import React from "react";
import PropTypes from "prop-types";

//  vscode is able to infer the types correctly in autocomplete
// as this is a functional component, with prop types
// Please note that vscode still does not show the correct types
// when hovering on the component usage

function MyComponent({ prop1, prop2, prop3 }) {
  return (
    <div>
      <span>{prop1}</span>
      <span>{prop2}</span>
    </div>
  );
}

MyComponent.propTypes = {
  prop1: PropTypes.string.isRequired,
  prop2: PropTypes.bool,
  prop3: PropTypes.shape({
    p1: PropTypes.string
  })
};

MyComponent.defaultProps = {
  prop2: false
};

export default MyComponent;
  1. At the point of usage, where you have imported this component, hover on the usage, you will see that vscode is able to identify the function signature, but not the types of the function arguments, and shows them as any
Screenshot 2021-07-21 at 1 30 58 AM
  1. If you hovber over the specific prop though, you would see that vscode shows the correct type (inferred from prop types) and also provides autocompletion for the prop name. (Although there is still an issue that it shows all the props as optional)
Screenshot 2021-07-21 at 1 31 04 AM
Example:

https://codesandbox.io/s/vscode-intellisense-proptypes-fc-w-destructuring-w-proptypes-cngth?from-embed=&file=/src/MyComponent.js:0-655

Expectation:

I would have expected that

  • vscode would be able to infer the types on hovering as well, same as it can do while providing autocomplete suggestion for the prop
  • vscode would not show all the props as optional, since it seems that it can infer prop names and types from prop types, it should also be able to infer whether it is required or optional.

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

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

はじめの一歩

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

調査の方向性

リンクされている CodeSandbox から始め、TypeScript 言語サービスで JSX コンポーネントのホバー動作を再現します。コンポーネントの使用箇所に対する quick info を、MyComponent.js の prop autocomplete および推論された PropTypes と比較します。ホバーに推論された prop の型が表示され、必須の prop とオプションの prop が区別されれば完了です。

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

評価

技術スタック
javascript, react, typescript
領域
developer-experience
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

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

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