microsoft / microsoft/TypeScript

class-factory mixins in type declaration files are impossible. (allow implicit return types in declaration files somehow)

Aperta
#35,715 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Search Terms

When the compiler is set to emit declaration files, class-factory mixins are no longer allowed. This is yet another issue that prevents class-factory mixins from being adopted in library code that need to be publish as JS with sibling declaration files.

Suggestion

Allow implicit return types to be somehow representable in declaration files.

Use Cases

Enables many use cases that are otherwise impossible when emitting declaration files. I believe declaration files should support all features of TS.

Examples

Write a mixin function, and try to emit declaration files.

Workaround

As a workaround I publish TypeScript source files in my NPM packages, then I point the types field in package.json to my source entry point. I don't publish declaration files because I can't build them.

Pointing to source files opens up other cans of worms, and prior to TS 3.6.3 I was not able to point to source files due to pre-existing bugs in tsc in that scenario. After TS 3.6.3, I can successfully publish source files and point types to sources containing class-factory mixins, but I'm afraid this is brittle and can break with an upgrade to TS (just as it was broken from some point prior to v3.6.3).

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 è indicato alcun file sorgente né alcun test. Inizia riproducendo l'esempio di class-factory mixin emettendo al contempo declaration files, quindi traccia il comportamento di declaration-emission coinvolto. Il lavoro è completato quando è possibile emettere una rappresentazione supportata del tipo di ritorno implicito del mixin senza richiedere il workaround di pubblicare file sorgente TypeScript.

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
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.