Microsoft/TypeScript

JS output contains imports only used in types when `emitDecoratorMetadata: true`

Open

#42,301 opened on Jan 12, 2021

View on GitHub
ย (0 comments)ย (0 reactions)ย (0 assignees)TypeScriptย (48,455 stars)ย (6,726 forks)batch import
BugDomain: DecoratorsHelp Wanted

Description

Bug Report

๐Ÿ”Ž Search Terms

  • emitDecoratorMetadata require
  • emitDecoratorMetadata import

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 3.3.3, 4.1.3

โฏ Playground Link

Playground link with relevant code

๐Ÿ’ป Code

import * as vscode from 'vscode';

function LogMethod(
  target: any,
  propertyKey: string | symbol,
  descriptor: PropertyDescriptor
) {
  console.log(target);
  console.log(propertyKey);
  console.log(descriptor);
}

class Demo {
  @LogMethod
  public foo(bar: vscode.Memento) {
    // do nothing
  }
}

const demo = new Demo();

๐Ÿ™ Actual behavior

The output contains const vscode = __importStar(require("vscode")); when emitDecoratorMetadata: true but not when emitDecoratorMetadata: false

๐Ÿ™‚ Expected behavior

As the type of bar as nothing to do with the compiled JS, the import of vscode should not exist regardless of the value of emitDecoratorMetadata

Contributor guide

JS output contains imports only used in types when `emitDecoratorMetadata: true` ยท Microsoft/TypeScript#42301 | Good First Issue