Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Resolve does not work as described in README #45

Closed
dyushin opened this issue Nov 9, 2023 · 1 comment
Closed

[BUG] Resolve does not work as described in README #45

dyushin opened this issue Nov 9, 2023 · 1 comment

Comments

@dyushin
Copy link

dyushin commented Nov 9, 2023

There is example in readme

function validateBody<T>(data: Assert<{ body: Resolve<T> }>) {
    return data.body;
}

const validatedBody = validateBody<{
    name: string,
    other: boolean
}>({ body: JSON.parse(process.argv[2]) });

// Transpiles to:
function validateBody(data) {
    return data.body;
}
const receivedBody = JSON.parse(process.argv[2]);
const validatedBody = (() => {
    const data = { body: receivedBody };
    if (typeof data.body !== "object" && data.body !== null)
        throw new Error("Expected data.body to be an object");
    if (typeof data.body.name !== "string")
        throw new Error("Expected data.body.name to be a string");
    if (typeof data.body.other !== "boolean")
        throw new Error("Expected data.body.other to be a boolean");
    return validateBody(data);
})();

I copied it to playground and instead of checking data.body i see null

function validateBody(data) {
    return data.body;
}
const validatedBody = (() => {
    const data = {
        body: JSON.parse(process.argv[2])
    };
    if (typeof data !== "object" || data === null)
        throw new Error("Expected data to be an object");
    if (typeof data.body !== "object" || data.body === null)
        throw new Error("Expected data.body to be an object");
    if (typeof null.name !== "string")
        throw new Error("Expected .name to be a string");
    if (typeof null.other !== "boolean")
        throw new Error("Expected .other to be a boolean");
    return validateBody(data);
})();
@GoogleFeud
Copy link
Owner

Thanks for the bug report!

GoogleFeud added a commit that referenced this issue Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants