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

import type can't be used with interface extends #36478

Closed
mjbvz opened this issue Jan 28, 2020 · 3 comments · Fixed by #36496
Closed

import type can't be used with interface extends #36478

mjbvz opened this issue Jan 28, 2020 · 3 comments · Fixed by #36496
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jan 28, 2020

TypeScript Version: 3.8.0-dev.20200128

Search Terms:

  • import type
  • extends interface

Code
For the TS:

import type * as iface from './iface';

interface Foo extends iface.IFace { }

Expected behavior:
No errors. iface is only being used as a type, not a value

Actual behavior:
Error:

'iface' cannot be used as a value because it was imported using 'import type'

This code previously did not produce errors in TS 3.8-beta

Related issues

/cc @andrewbranch

@bolinfest
Copy link

This is marked "closed," but I am still seeing this issue on TypeScript 3.8.3.

TypeScript Version: 3.8.3

Search Terms: import type

Code

import type * as monaco from "monaco-editor";

// Trying to create a subtype of IViewZone that provides
// a guarantee that marginDomNode is not null.
interface MyViewZone extends monaco.editor.IViewZone {
  marginDomNode: HTMLElement;
}

Expected behavior:
This should typecheck.

Actual behavior:

error TS1361: 'monaco' cannot be used as a value because it was imported using 'import type'.

24 interface MyViewZone extends monaco.editor.IViewZone {
                                      ~~~~~~

  src/zoneManager.ts:5:13
    5 import type * as monaco from "monaco-editor";
                  ~~~~~~~~~~~
    'monaco' was imported here.

Note that in the same file, I can do:

type ZoneWidget = {
  afterLineNumber: number;
  zone: monaco.editor.IViewZone;
};

so it is surprising that I can use monaco.editor.IViewZone in one place but not the other.

Playground Link:
Unfortunately, I cannot repro in a playground as I would expect. Perhaps this is something specific to monaco-editor? For example, doing something analogous with the http Node built-in works fine:

https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=5&pc=2#code/JYWwDg9gTgLgBDAnmApnAVHAhgZzgCxhjDgDMoIQ4AiQ46gbgCgngA7GFKUrAYzQCyiAMIAbYCg4AlFAEcArihwwAglADmeFAA9ObACZ46YAHRiJ0uYuVrNcAN5M4zuGAowIvCKIBccZVDs6swAvkA

Related Issues: This one!

@bolinfest
Copy link

I suspect it has to do with the depth into the namespace? It appears I could do this:

import type * as monaco from "monaco-editor";

interface MyViewZone extends monaco.IRange {
  marginDomNode: HTMLElement;
}

but not this:

import type * as monaco from "monaco-editor";

interface MyViewZone extends monaco.editor.IViewZone {
  marginDomNode: HTMLElement;
}

@bolinfest
Copy link

Ah, though as a workaround I can do:

import type * as monaco from "monaco-editor";
type IViewZone = monaco.editor.IViewZone;

interface MyViewZone extends IViewZone {
  marginDomNode: HTMLElement;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants