microsoft / microsoft/TypeScript
"types" field in package.json pointing to a `.ts` file in node_modules results in the file being compiled and type checked
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Continuing from https://github.com/Microsoft/TypeScript/issues/22228
cc @evil-shrike
I have this issue.
@mhegazy said
the lib has either
"types": "index.ts"or a.tsfile at its root. which is wrong. a library should not expose its sources, only its declarations.
But features like inferred return types (f.e. when making class-factory mixins) are not compilable to declaration files, resulting in errors like
error TS4025: Exported variable 'html' has or is using private name 'htmlBind'.
error TS4031: Public property '_currentArea' of exported class has or is using private name 'AreaInternal'.
error TS4055: Return type of public method from exported class has or is using private name 'PartHelper'.
error TS4073: Parameter 'partHelper' of public method from exported class has or is using private name 'PartHelper'.
error TS4078: Parameter 'options' of exported function has or is using private name 'ExtendOptions'.
A .d.ts does not have expressions.. it represents the shape of the API.
Not entirely true.
As far as I know, the only way to use features (that declaration files don't support) in downstream projects is to get types directly from .ts source files. This makes the need to point types to .ts source files a valid use case.
This is what I think should happen:
If "types" points to a .ts file, and "main" points to a .js file, then the compiler should use the .ts file only for type definitions and not compile or type-check the code.
"main" can serve as a guide to telling the compiler whether it should compile sources, or read js files. "types" should be for... specifying the source of types.
Unless I missed it, there's no other way to include types for features that aren't representable in declaration files.
Why is it that declaration features don't match source features? It seems that an important goal should be for declaration features to always have the capability of matching source features.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die hier beschriebene package.json-Konfiguration nachzubilden, wobei types auf eine .ts-Datei und main auf eine .js-Datei zeigt; sieh dir zur Einordnung die Diskussion in Issue #22228 an. Als erledigt gilt die Aufgabe, wenn der Compiler den .ts-Einstiegspunkt für Typinformationen verwendet, ohne dessen Implementierung zu kompilieren oder einer Typprüfung zu unterziehen, und dabei das gewünschte Typisierungsverhalten für nachgelagerten Code beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100