-
Notifications
You must be signed in to change notification settings - Fork 12.8k
import type cannot be used on classes? #36040
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
Comments
Hm - I suppose the workaround is to use let Terminal: typeof import("xterm").Terminal;
let WebLinksAddon: typeof import("xterm-addon-web-links").WebLinksAddon;
let SearchAddon: typeof import("xterm-addon-search").SearchAddon;
let WebglAddon: typeof import("xterm-addon-webgl").WebglAddon; I do think that this is working as intended, but I think it begs the question of whether we need |
|
Ugh, then you'll really have to write the moral equivalent of a type XTermTerminal = typeof import("xterm").Terminal;
type XTermWebLinksAddon = typeof import("xterm-addon-web-links").WebLinksAddon;
type XTermSearchAddon = typeof import("xterm-addon-search").SearchAddon;
type XTermWebglAddon = typeof import("xterm-addon-webgl").WebglAddon;
let Terminal: XTermTerminal;
let WebLinksAddon: XTermWebLinksAddon;
let SearchAddon: XTermSearchAddon;
let WebglAddon: XTermWebglAddon; |
This seems to work but I question the usefulness of import type if I can't even use it with my dynamic imports, what other cases would you want to strictly import only types? type XTermTerminal = import('xterm').Terminal;
type XTermTerminalCtor = typeof import('xterm').Terminal;
type XTermWebLinksAddonCtor = typeof import('xterm-addon-web-links').WebLinksAddon;
type XTermSearchAddonCtor = typeof import('xterm-addon-search').SearchAddon;
type XTermWebglAddonCtor = typeof import('xterm-addon-webgl').WebglAddon;
let Terminal: XTermTerminalCtor;
let WebLinksAddon: XTermWebLinksAddonCtor;
let SearchAddon: XTermSearchAddonCtor;
let WebglAddon: XTermWebglAddonCtor; |
Is there some easier way to use an interface as a class? It seems ugly to have to spell out the constructor interface? |
See microsoft/vscode#88222 for that approach |
@andrewbranch per our Teams discussion it sounds like we landed on allowing |
I was excited when I heard about
import type
as I've been using dynamic imports on a component to save start up time in vscode for some time, however it's very fragile as I only want to import types and not implementation.When I try to put the
import type
guard in place I get the following error though:What's happening here is I'm wanting to import an
export class
definition and only reference it as a type by getting its constructor withtypeof
. However I'm getting an error that it's being used as a value inside a:
type definition?Terminal definition: https://github.com/xtermjs/xterm.js/blob/1c06e576aea6b1a63dc71d180ae92cc1c6d68c7c/typings/xterm.d.ts#L385
Above usage: https://github.com/microsoft/vscode/blob/81fb34c445098d43d0f25b4e1868ca421022d4de/src/vs/workbench/contrib/terminal/browser/terminalInstanceService.ts#L8-L16
The text was updated successfully, but these errors were encountered: