Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit keyword for type-only import #20433

Closed
rokoroku opened this issue Dec 4, 2017 · 2 comments
Closed

Explicit keyword for type-only import #20433

rokoroku opened this issue Dec 4, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@rokoroku
Copy link

rokoroku commented Dec 4, 2017

I'd like to suggest an explicit keyword for type-only import. e.g.

Suggestion

// moduleA.ts
export class ClassA {
  ...
  static someStaticFn(class: ClassA) { ... }
}

// moduleB.ts
import type { ClassA } from './moduleA';

export function aFunction(classA: ClassA) {
  ClassA.someStaticFn(classA); 
  ~~~~~
  cannot use type-only imports as a real expression!
}

Related:
https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-imports-being-elided-in-my-emit


Purpose

The type-only import (which are elided in the output file) is really useful when writing argument types. However, we sometimes mistakenly use imported variables as the real expression, which sometimes causes circular dependency errors.

If we have an explicit keyword for that kind of imports, it will help reduce the errors.

Is there any feature to achieve this scenario?

@mhegazy
Copy link
Contributor

mhegazy commented Dec 4, 2017

originally proposed in #2812 and rejected

#9191 is now used to track addressing the scenario in general.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 4, 2017
@rokoroku
Copy link
Author

rokoroku commented Dec 5, 2017

Got it. Thanks :)

@rokoroku rokoroku closed this as completed Dec 5, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants