microsoft / microsoft/TypeScript
Merging constants with namespaces
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
I wrote this in closed #13536 first, but thought it might get lost there, so filing a new issue.
Merging consts with namespaces really makes sense. For a real-world example, let's take a popular library: TinyMCE, writing proper type definitions for which requires this feature. Namespaces are really convenient in this case because all the classes from the API are attached to the tinymce namespace object or to its subnamespaces. In the API, there are normal classes like tinymce.Editor and so called 'static classes' like tinymce.EditorManager which are just a type (interface) plus an object value of this type attached to the namespace:
declare namespace tinymce {
// normal class
class Editor {
show(): void;
// ...
}
// "static class"
interface EditorManager {
activeEditor: Editor;
// ...
}
const EditorManager: EditorManager;
// ...
}
Nothing unusual so far, but there is a plot twist. The namespace object tinymce itself implements the tinymce.EditorManager interface. It could be easily and beautifully solved by merging a const with the namespace:
declare const tinymce: tinymce.EditorManager;
declare namespace tinymce {
// ... see the previous snippet
}
But unfortunately this isn't allowed. The error message is: Cannot redeclare block-scoped variable 'tinymce'.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo gli snippet di dichiarazione di tinymce e leggendo il comportamento di fusione delle dichiarazioni che produce l’errore segnalato di redeclarazione nell’ambito del blocco. Il lavoro è completato quando const e lo spazio dei nomi possono essere uniti per questo esempio senza introdurre regressioni nelle regole di dichiarazione esistenti.
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
- 35/100