timocov / ts-transformer-properties-rename

TypeScript custom transformer to rename properties
MIT License
70 stars 3 forks source link

Mapped types do not respect @public jsdoc #15

Closed 87vrvk9k closed 4 years ago

87vrvk9k commented 4 years ago

Mapped types do not appear to respect @public jsdoc

/** @public */
export type TestKey = "a" | "b";
/** @public */
export type TestMappedType = {
  /** @public */
  [P in TestKey]?: {};
};

class TestMappedClass {
  /** @public */
  private testMapped: TestMappedType = {};
  public constructor() {
    this.testMapped.a = {};
  }
}

Results in

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TestMappedClass = /** @class */ (function () {
    function TestMappedClass() {
        /** @public */
        this._private_testMapped = {};
        this._private_testMapped._internal_a = {};
    }
    return TestMappedClass;
}());

Note: I tried it using Record as well and it has the same issue

timocov commented 4 years ago

@chrisd08 expected output here is:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TestMappedClass = /** @class */ (function () {
    function TestMappedClass() {
        this._private_testMapped = {};
        this._private_testMapped.a = {};
    }
    return TestMappedClass;
}());

am I right (don't rename a)?

87vrvk9k commented 4 years ago

@timocov Yes that's correct

timocov commented 4 years ago

Fixed in 74ed470. If a mapped type is exported, you don't need to mark it as public now. But anyway, if a mapped type isn't exported, you can mark the whole type as public in this case (instead of indexer or property keys) (see added test cases for the reference).

timocov commented 4 years ago

The fix is just published in 0.8.0 version. Let me know if you have any further issues.