英文:
import "type" and "different variable" in one single line
问题
我是新手 TypeScript。目前,我正在尝试在 Electron 应用程序中使用 TypeScript(只是练习 TypeScript)。
在我的应用程序中,我需要从 electron 包中导入一个“type”和一个“variable/class”,但目前我是这样做的:
import { dialog } from 'electron';
import type { BrowserWindowConstructorOptions } from 'electron';
有没有办法让它成为一行,同时仍然清楚地显示我正在导入的内容(“type”或“variable/class”)?
我知道我可以像这样做:
import { dialog, BrowserWindowConstructorOptions } from 'electron';
但使用上面的代码,不清楚我正在导入的是什么,很难判断我导入的“dialog”是一个类型还是一个变量。
英文:
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
得分: 7
你可以在所选的导入之前使用 type
关键字来指定类型:
import { dialog, type BrowserWindowConstructorOptions } from 'electron';
这在 TypeScript 文档的 Modules > Importing Types 部分有详细说明。
英文:
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 > Importing Types section in TypeScript docs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论