profile
viewpoint

Ask questionsimport type can't be used with interface extends

<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨

Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a bug, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section!

Please help us by doing the following steps before logging an issue:

  • Search: https://github.com/Microsoft/TypeScript/search?type=Issues
  • Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ

Please fill in the entire template below. -->

<!-- Please try to reproduce the issue with the latest published version. It may have already been fixed. For npm: typescript@next This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly --> TypeScript Version: 3.8.0-dev.20200128

<!-- Search terms you tried before logging this (so others can find this issue more easily) --> 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

  • #36428

/cc @andrewbranch

microsoft/TypeScript

Answer questions bolinfest

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

TypeScript Version: 3.8.3

<!-- Search terms you tried before logging this (so others can find this issue more easily) --> 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!

useful!

Related questions

Why `window.location.reload(true)` is deprecated? hot 9
Suppressing "The import path cannot end with a '.ts' extension" error? hot 3
Cannot export { ... } interface when --isolatedModules is passed hot 3
TS2739: Type is missing the following properties from type hot 3
TSC Strict mode error TS2722: Cannot invoke an object which is possibly 'undefined'. hot 2
This condition will always return 'false' since the types have no overlap. hot 2
Allow extending types referenced through interfaces hot 2
Add ES2019 Object.fromEntries function hot 2
Property 'setState' does not exist on type 'App'.ts(2339) hot 2
File differs from already included file only in casing: correct casing but relative path hot 2
Cannot find name 'MediaRecorder'. hot 2
tsc.ps1 cannot be loaded. The file ... is not digitally signed hot 2
error TS1183: An implementation cannot be declared in ambient contexts. hot 2
3.7.2 Promise.all does infers base type of interfaces rather than actual interface hot 1
Skip typechecking; only emit (support `--transpileOnly` in `tsc`, re-open of #4176) hot 1
source:https://uonfu.com/
Github User Rank List