microsoft / microsoft/TypeScript

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

Offen
#23,472 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Domain: JavaScript Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem checkJs-Beispiel in create-react-app/packages/react-error-overlay/src/utils/parseCompileError.js und vergleiche das Verhalten des language-service mit der Batch-Kompilierung. Verfolge, wie Typdeklarationen und Annotationen ErrorLocation sowie die inferierten Typen von message und lines beeinflussen. Als abgeschlossen gilt, dass Fehler in Annotationen bestehen bleiben, während nicht verwandte JavaScript-Dateien in beiden Modi weiterhin ihre eigenen Typfehler melden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.