GoogleFeud / ts-runtime-checks

A typescript transformer that automatically generates validation code from your types.
https://googlefeud.github.io/ts-runtime-checks/
MIT License
312 stars 7 forks source link

[BUG] Build will fail if the property name contains special characters. #63

Open rmagur1203 opened 1 month ago

rmagur1203 commented 1 month ago

Describe the bug Properties are accessed using PropertyAccessExpression, but must use ElementAccessExpression that contain special characters.

Playground link playground

Expected behavior

function validate(user) {
    if (typeof user !== "object" || user === null)
        throw new Error("Expected user to be User");
    if (typeof user.name !== "string")
        throw new Error("Expected user.name to be a string");
    if (typeof user.id !== "number" || user.id < 10)
        throw new Error("Expected user.id to be a number, to be greater than 10");
    if (typeof user.obj !== "object" || user.obj === null)
        throw new Error("Expected user.obj to be an object");
    if (typeof user.obj["a-special-key"] !== "string")
        throw new Error("Expected user.obj.a-special-key to be a string");
}
validate({
    name: "abc",
    id: 4,
    obj: {
        'a-special-key': "test"
    }
});

Additional context Add any other context about the problem here.