You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
})();
The text was updated successfully, but these errors were encountered:
There is example in readme
I copied it to playground and instead of checking
data.body
i seenull
The text was updated successfully, but these errors were encountered: