microsoft / microsoft/TypeScript
Clean up syntax for importing and using nested type declarations
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Search Terms
- import
- import equals
- nested import
Suggestion
The current syntax for importing nested modules is confusing. For example, to specifically use a single property from an interface I would need to do something like this:
// interface.ts
interface Example {
Foo: string
}
// file.ts
import { Example } from 'interface.ts';
import Foo = Example.Foo // this is weird, as I'm not actually importing any resource here
From what I understand, import is not importing anything here. It's confusing and looks like it's doing something totally different at first glance. In this case, I could also use type Bind = interfaces.Bind, but I don't want to create a new resource.
A much nicer syntax would be adding a use or take keyword, or adding support for importing nested modules
Use Cases
This suggestion is just for readability and developer experience.
Examples
Importing nested modules with use or take
// interface.ts
interface Example {
Foo: string
}
// file.ts
import { Example } from 'interface.ts';
take { Foo } from Example;
importing nested interface/namespace values:
// interface.ts
interface Example {
Foo: string
}
// file.ts
import { Example: { Foo } } from 'interface.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
- 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
Esamina gli esempi di dichiarazioni annidate in interface.ts e file.ts, inclusa la forma import-equals esistente e le forme use, take e nested-import proposte. Determina la sintassi prevista e il comportamento del controllo dei tipi prima di prendere in considerazione l’implementazione; per considerarlo completato sarebbero necessari un design concordato e test del compilatore e di regressione, nessuno dei quali è identificato nell’issue.
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