microsoft / microsoft/TypeScript
Improve quick info on JSX component elements
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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:
- 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;
- 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
- 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)
Example:
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verknüpften CodeSandbox und reproduziere das JSX-Komponenten-Hover-Verhalten im TypeScript-Sprachdienst. Vergleiche die quick info für die Verwendung der Komponente mit der prop autocomplete und den inferred PropTypes in MyComponent.js. Als erledigt gilt die Aufgabe, wenn der Hover die abgeleiteten Prop-Typen anzeigt und erforderliche von optionalen Props unterscheidet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react, typescript
- Bereich
- developer-experience
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100