microsoft / microsoft/TypeScript

Type checking and IntelliSense with JSDoc typed js dependencies

Offen
#29,824 5 Kommentare 14 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Search Terms

JSDoc types dependenies

Suggestion

Possible alternative to #7546: Maybe type checking from JSDoc annotated dependencies can be achieved more easily in a different way. I have created a gist with a demo project that successfully uses a dependency (ol@6.0.0-beta.1 with fully JSDoc typed sources. This works well to get IntelliSense in VS Code for projects authored in pure JavaScript, but requires a not very obvious jsconfig.json configuration. Similar configurations (with tsconfig.json) partially work with TypeScript projects, but are very fragile quite easily, especially in more complex projects. And they only work when the "noEmit": true option is used.

However, it looks like a much lower hanging fruit than making .d.ts file generation work from JSDoc annotated JavaScript code (#7546). As the above example shows, it works already, but it should work out of the box and also in more complex configurations with TypeScript.

Use Cases

Full type checking and tsc support in both JavaScript and TypeScript projects with pure JavaScript dependencies. The dependencies are either JSDoc typed directly or published with their JSDoc typed sources.

This has to work without .d.ts files, because these cannot be generated from .js sources, neither with tsc nor reliably with third party applications.

Examples

Two possible scenarios:

  1. A package that only contains untranspiled JSDoc-typed modules. Unrealistic, because class inheritance is only fully recognized by TypeScript when the ES2015 class and extends keywords are used, which packages don't usually do, because it limits interoperability.
  2. A package that contains transpiled modules in addition to the original JSDoc-typed sources. Realistic and feasible, especially when source maps can point to these sources directly. An example for this would be ol@6.0.0-beta.1.

So let's assume the latter case is the more common one. If TypeScript would look for a tsconfig.json in dependencies (e.g. node_modules/ol/tsconfig.json), that file could have a config option to point to the annotated sources. Maybe something like

{
  "compilerOptions": {
    "jsSources": [
      "src/**/*.js"
    ]
  }
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

Reproduziere das verlinkte Gist und vergleiche die in der Issue beschriebenen Konfigurationen von jsconfig.json und tsconfig.json. Beginne damit nachzuverfolgen, wie TypeScript JavaScript-Abhängigkeiten und deren mit JSDoc annotierte Quellen auflöst; als erledigt gilt die Aufgabe, wenn Typprüfung und IntelliSense für JavaScript- und TypeScript-Projekte funktionieren, ohne .d.ts-Dateien oder noEmit zu erfordern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers, developer-experience
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

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