microsoft / microsoft/TypeScript

Improve quick info on JSX component elements

Abierto
#45,140 7 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Domain: LS: Quick Info Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el CodeSandbox enlazado y reproduce el comportamiento del hover del componente JSX en el servicio de lenguaje de TypeScript. Compara la quick info del uso del componente con la prop autocomplete y los PropTypes inferidos en MyComponent.js. Se considera completado cuando el hover muestra los tipos de props inferidos y distingue entre props obligatorias y opcionales.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, react, typescript
Área
developer-experience
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.