microsoft / microsoft/TypeScript

Allow type annotations in .js files in preparation for Type Annotations proposal

Aperta
#59,648 0 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.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔍 Search Terms

allow js file extension

✅ Viability Checklist
⭐ Suggestion

Add an option to allow removing the error "[some feature] can only be used in TypeScript files"

Previous discussion: #10939

The compiler option would allow consuming .js files as if they were .ts files, but with some differences (see below). All type-checking, type-stripping, and code emitting features would remain as-is.

📃 Motivating Example

The Type Annotations proposal is the definite future of JavaScript.

This feature would:

  • Enable incremental adoption of the Type Annotations proposal by users
  • Enable incremental support of Type Annotations in the TypeScript compiler
  • Possibly help push that proposal forward a little more quickly by increased usage
  • Spread word that this proposal exists by gaining compiler support in tsc and its release notes

It's true that the exact syntax isn't definite yet, and it will probably be at least somewhat different than current TypeScript syntax.

However, that's exactly why adding initial support for plain TypeScript would not interfere with its eventually sealed syntax.

In other words, the initial support would simply parse it as "typed-javascript" but the TypedJavaScript parser would currently be exactly the same as the TypeScript parser for the time being, and allow gradual differentiation.

It would also be a good opportunity to allow TypedJavaScript mode to disallow namespaces, enums, constructor fields, etc.

💻 Use Cases
  1. What do you want to use this for?

Writing future-ready JavaScript.

  1. What shortcomings exist with current approaches?

It doesn't take into account the pending type annotation proposal.

  1. What workarounds are you using in the meantime?

I can almost get this working with some VS Code hacks, but then tsc complains as soon as I run it.

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

Inizia leggendo la discussione precedente in #10939 e la proposta TC39 Type Annotations collegata. Esamina quindi le restrizioni esistenti del compilatore TypeScript sulla sintassi esclusiva di TypeScript nei file .js e determina l'ambito dell'opzione, compresi i costrutti che devono rimanere non consentiti. Il lavoro è completato quando un'opzione documentata del compilatore supporta il parsing previsto di JavaScript tipizzato senza modificare il comportamento di runtime emesso.

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

Valutazione

Stack tecnologico
javascript, 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
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.