-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Hi @aenario !
I'm curious; what do you think of a Babel plugin that would transpile this:
type Todo = {
userId: number;
id: number;
title: string;
completed: boolean;
}
const resp = await fetch("https://jsonplaceholder.typicode.com/todos/1");
const data = await resp.json();
assert(data typeof Todo);to that:
const __TodoType = {
userId: Number;
id: Number;
title: String;
completed: Boolean;
};
const __isTodoType = obj => (
obj &&
obj.constructor === Object &&
Object.keys(obj).length === Object.keys(__TodoType).length &&
Object.entries(obj)
.every(([prop, val]) =>
__TodoType[prop] && val &&
__TodoType[prop] === val.constructor)
);
const resp = await fetch("https://jsonplaceholder.typicode.com/todos/1");
const data = await resp.json();
assert(__isTodoType(data));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels