timocov / ts-transformer-properties-rename

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

Incorrect handling unknown/any casting #25

Closed timocov closed 3 years ago

timocov commented 3 years ago

Bug report

Input code

function func(): unknown {
    const b = { value: 321 } as unknown;
    const c = { int: 222 } as unknown as InternalInterface;

    return {
        foo: 1,
        bar: b,
        baz: 3,
        c: c,
    };
}
function func2(): any {
    const b = { value: 321 } as any;
    const c = { field: 222 } as any as InternalInterface;
    return {
        foo: 1,
        bar: b,
        baz: 3,
        c: c,
    };
}

Expected output

function func() {
    var b = { value: 321 };
    var c = { _internal_int: 222 };

    return {
        foo: 1,
        bar: b,
        baz: 3,
        c: c,
    };
}
function func2() {
    var b = { value: 321 };
    var c = { _internal_field: 222 };

    return {
        foo: 1,
        bar: b,
        baz: 3,
        c: c,
    };
}

Actual output

function func() {
    var b = { _internal_value: 321 };
    var c = { _internal_int: 222 };

    return {
        _internal_foo: 1,
        _internal_bar: b,
        _internal_baz: 3,
        _internal_c: c,
    };
}
function func2() {
    var b = { _internal_value: 321 };
    var c = { _internal_field: 222 };

    return {
        _internal_foo: 1,
        _internal_bar: b,
        _internal_baz: 3,
        _internal_c: c,
    };
}