Skip to content

transpileModule does not elide type only "import equals" under emitDecoratorMetadataΒ #55570

Open
@frigus02

Description

@frigus02

πŸ”Ž Search Terms

isolatedModules import alias

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried: v5.1.1, v5.2.2, v5.3.0-dev.20230830

⏯ Playground Link

https://www.typescriptlang.org/play?importHelpers=true&experimentalDecorators=true&emitDecoratorMetadata=true&isolatedModules=true&noResolve=true&ts=5.3.0-dev.20230830#code/JYWwDg9gTgLgBAbwJIDsYFMoDMCGBjdAXziyghDgHIA6AehgE8x0BnSgbgChPRJY4AcqwwATVBmz50cALxxxmXAWpCWohZIJdOI9HgA2OKNLwQUa+SjABXGAC44OFA23oAHn3gGcLFnABiEBCInHBhcAACqDbwYGRgAIQOqupoilJchEA

πŸ’» Code

import {Interface} from './types';

import NestedInterface = Interface.NestedInterface;

declare const Input: any;

export class Foo {
    @Input prop!: NestedInterface;
}

πŸ™ Actual behavior

var _a;
import { __decorate, __metadata } from "tslib";
import { Interface } from './types';
var NestedInterface = Interface.NestedInterface; // <-- this can throw at runtime
export class Foo {
}
__decorate([
    Input,
    __metadata("design:type", typeof (_a = typeof NestedInterface !== "undefined" && NestedInterface) === "function" ? _a : Object)
], Foo.prototype, "prop", void 0);

πŸ™‚ Expected behavior

Either of the following would work, I think:

  • Make this pattern an error, possibly requiring sth like import type NestedInterface = Interface.NestedInterface;
  • Elide import equals
  • Emit var NestedInterface = ... using a runtime check, similarly as in the decorator metadata code

Additional information about the issue

Very similar to #49450

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: DecoratorsThe issue relates to the decorator syntaxRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions