Microsoft/TypeScript

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

Open

#42,301 创建于 2021年1月12日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)TypeScript (48,455 star) (6,726 fork)batch import
BugDomain: DecoratorsHelp Wanted

描述

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

贡献者指南