Skip to content

No-op string in constructor is repeated and reordered when constructor assignment is used #48671

Closed
@rhuitl

Description

@rhuitl

Bug Report

The TypeScript code

class Example {
    constructor(private A: string) {
        "ngInject";
    }
}

when compiled with TS 4.6.2 yields:

"use strict";
class Example {
    constructor(A) {
        this.A = A;
        "ngInject";
        "ngInject";
    }
}

when compiled with TS 4.5.5 yields:

"use strict";
class Example {
    constructor(A) {
        "ngInject";
        this.A = A;
    }
}

The differences are:

  • the string "ngInject;" is repeated
  • the string appears after the constructor assignment, not before as in 4.5.

For our use case, the repetition is probably not a real problem, however the re-ordering is. If any of these two are by design now, we can work around - but I wanted to double check with the TypeScript developers because it seems to be a bit unexpected.

🕗 Version & Regression Information

We observed errors in a AngularJS-based project using ng-annotate-patched which relies on the string to annotate classes for AngularJS. It works wiht TS 4.5 and broke with TS 4.6.

TS 4.6.2 (broken)
TS 4.5.5 (good)

⏯ Playground Link

https://www.typescriptlang.org/play?removeComments=true&target=2&ts=4.5.5#code/MYGwhgzhAECiAeYC2AHEBTaBvAUASGAHsA7CAFwCcBXYMwigChQoEsA3MMzAQQC5pyrYgHMAlNnx4ARCICSxAFbpaUgNz4Avji1A

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions