microsoft / microsoft/TypeScript

Emit .d.ts for type-only usage of .d.ts files in a project

Aperta
#38,146 0 commenti 13 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Proposal Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Search Terms

type only export import declaration declarations .d.ts 3.8

Suggestion

When building code has .d.ts files written and used internally, the declarations aren't emitted. This makes sense currently because .d.ts files aren't compiled. However, it causes typechecking errors when exporting content from the package for external usage, since the declaration isn't included in the compiled output.

import/export type made some initial progress for me by removing the types from the compiled JS output. but I believe it would be even more useful to re emit declarations for type only import exports. this would ensure that ambient declarations are included in the final compiled output.

My issue may be incorrect usage of declaration files, which I've only been using due to the external code generation using it. I'm not sure I explained my idea clearly, but I believe my below examples should cover it - please follow up if not.

Use Cases

I have an existing project that exports declarations generated by an external package from non-JS code. The original code doesn't need to be included, just the types for usage by external consumers. When I want to reexport those declarations, I have to manually copy them over to the build folder after since they disappear. You can see an example of this here

Examples

given directory structure

./src/index.ts
./src/generated.d.ts

and usage

// ./src/index.ts
import type Foo from './generated.d.ts'

the output structure should be

./dist/index.js
./dist/index.d.ts
./dist/generated.d.ts

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.

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

Non vengono indicati file sorgente o test. Inizia tracciando la gestione di TypeScript dell’emissione delle dichiarazioni per gli import costituiti solo da tipi e per gli input .d.ts, quindi confrontala con l’esempio src-to-dist richiesto; il lavoro è completato quando l’output generato include la dichiarazione referenziata senza modificare l’output JavaScript.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.