microsoft / microsoft/TypeScript

Clean up syntax for importing and using nested type declarations

Offen
#39,935 2 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Überprüfe die Beispiele für verschachtelte Deklarationen in interface.ts und file.ts, einschließlich der vorhandenen import-equals-Form und der vorgeschlagenen use-, take- und nested-import-Formen. Bestimme die beabsichtigte Syntax und das Verhalten der Typprüfung, bevor du eine Implementierung in Betracht ziehst; als erledigt würde dies ein abgestimmtes Design sowie Compiler- und Regressionstests erfordern, von denen im Issue keine identifiziert sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.