timocov / ts-transformer-properties-rename

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

Incorrect handling mapped types #16

Closed timocov closed 4 years ago

timocov commented 4 years ago

Bug report

Input code

interface Foo {
    field: string;
    field2: number;
}

type ReadonlyFoo = Readonly<Foo>;

function bar(foo: ReadonlyFoo): void {
    console.log(foo.field, foo.field2);
}

function baz(): void {
    const foo: Foo = {
        field: '',
        field2: 0,
    };

    bar(foo);

    bar({
        field: '',
        field2: 0,
    });
}

Expected output

function bar(foo) {
    console.log(foo._internal_field, foo._internal_field2);
}
function baz() {
    var foo = {
        _internal_field: '',
        _internal_field2: 0,
    };
    bar(foo);
    bar({
        _internal_field: '',
        _internal_field2: 0,
    });
}

Actual output

function bar(foo) {
    console.log(foo.field, foo.field2);
}
function baz() {
    var foo = {
        _internal_field: '',
        _internal_field2: 0,
    };
    bar(foo);
    bar({
        field: '',
        field2: 0,
    });
}

Additional context

Broken in #15