Skip to content

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

Closed

Description

@mjbvz

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 Andrew Branch (@andrewbranch)

Activity

  1. added
    Fix Available
    on Jan 29, 2020
  2. bolinfest commented on Mar 6, 2020

    @bolinfest

    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!

  3. bolinfest commented on Mar 6, 2020

    @bolinfest

    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;
    }
  4. bolinfest commented on Mar 6, 2020

    @bolinfest

    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;
    }
  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugFix Available

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ Proxy