6

I am new to Typescript. Currently I am trying to use TypeScript in an electron app(just practice TypeScript).

In my app I need to import a "type" and a "variable/class" in to my app from electron package, but currently I am doing it this way:

import { dialog } from 'electron';
import type { BrowserWindowConstructorOptions } from 'electron';

Is there a way I can make it one line while still clearly show what I am importing(a "type" or a "variable/class")?

I know that I can do something like this:

import { dialog ,BrowserWindowConstructorOptions } from 'electron';

but with above code, it's not clear what I am importing, it's hard to tell if the "dialog" I am importing is a type or a variable.

1 Answer 1

14

To specify type for selected imports, you may use type keyword before the imported name:

import { dialog, type BrowserWindowConstructorOptions } from 'electron';

This is documented under Modules - Reference > Module Syntax > Type-only imports and exports section in TypeScript docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.