microsoft / microsoft/TypeScript
In JS, type annotations should not block errors from the rest of the program
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
In a Javascript file that is checked by flow, we may see code like this (from create-react-app/packages/react-error-overlay/src/utils/parseCompileError.js)
export type ErrorLocation = {|
fileName: string,
lineNumber: number,
colNumber?: number,
|}
function parseCompileError(message: string): ?ErrorLocation {
const lines: Array<string> = message.split('\n');
for (let i = 0; i < lines.length; i++) {
// ...................
return fileName && lineNumber ? { fileName, lineNumber, colNumber } : null;
}
This behaves badly when the typescript compiler compiles it with checkJs on:
Expected behavior:
- Errors on the type declaration and all the type annotations.
- However, ErrorLocation should be declared as a type alias, and message, lines, etc should all have their declared types.
- If they are used incorrectly, they should have errors.
Actual behavior:
- Errors on the type declaration and all the type annotations.
In the language service:
2. message, lines, etc have the correct types, but ErrorLocation is type any.
3. If they are used incorrectly, they have errors.
In batch compilation:
2. No errors show up except those from (1), even if there are lots of other javascript files without type annotations.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el ejemplo de checkJs en create-react-app/packages/react-error-overlay/src/utils/parseCompileError.js y compara el comportamiento de language-service con la compilación por lotes. Rastrea cómo las declaraciones de tipos y las anotaciones afectan a ErrorLocation y a los tipos inferidos de message y lines. Se considera terminado cuando los errores de anotación permanecen, mientras que los archivos JavaScript no relacionados continúan informando de sus propios errores de tipo en ambos modos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100