microsoft / microsoft/TypeScript
Clean up syntax for importing and using nested type declarations
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the nested declaration examples in interface.ts and file.ts, including the existing import-equals form and the proposed use, take, and nested-import forms. Determine the intended syntax and type-checking behavior before considering implementation; done would require an agreed design plus compiler and regression tests, none of which are identified in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100