Object validation with proxies
Validating props using proxies:
const cell = {
title: '',
value: ''
}
const handler = {
set(target, property, value) {
if (property === "title") {
if (typeof value !== "string") {
throw new Error("title must be a string.");
}
}
target[property] = value;
}
};
const proxyCell = new Proxy(cell, handler);
cell.title = 123; // error