microsoft / microsoft/TypeScript

In JS, type annotations should not block errors from the rest of the program

Aperta
#23,472 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Domain: JavaScript Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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:

  1. Errors on the type declaration and all the type annotations.
  2. However, ErrorLocation should be declared as a type alias, and message, lines, etc should all have their declared types.
  3. If they are used incorrectly, they should have errors.

Actual behavior:

  1. 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con l'esempio checkJs in create-react-app/packages/react-error-overlay/src/utils/parseCompileError.js e confronta il comportamento di language-service con la compilazione batch. Traccia il modo in cui le dichiarazioni di tipo e le annotazioni influiscono su ErrorLocation e sui tipi inferiti di message e lines. Il lavoro è completato quando gli errori nelle annotazioni rimangono presenti, mentre i file JavaScript non correlati continuano a segnalare i propri errori di tipo in entrambe le modalità.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.