resclient
resclient copied to clipboard
Define underscore properties as non-enumerable
As it sits currently, models can be very hard to read when logged due to the numerous underscored properties (which I assume to be private, "don't use this" properties). These properties are shown when logging to the console, and you have to go out of your way to hide them, or sift through them for the actual data on the model. This can be combatted with simple defineProperty
/defineProperties
call
const obj = {};
Object.defineProperty(obj, "hidden1", { value: "whatever", enumerable: false });
Object.defineProperty(obj, "_hidden2", { value: "hi", enumerable: false });
Object.defineProperties(obj, {
hidden3: {
value: "this is easy",
enumerable: false
},
_hidden4: {
value: "please my adhd is killing me",
enumerable: false
}
});
console.log(obj);
console.log(obj.hidden1);
console.log(obj._hidden2);
console.log(obj.hidden3);
console.log(obj._hidden4);
The first log shows no properties, but the next 4 clearly show them as still accessible and usable.
It would also be nice (at least for types) to have things like ResError
exported at the top level, so we don't need tomfoolery like this to use the type
the isResError
function could also be defined as isResError(o: any): o is ResError
to actually narrow the type down
without:
with:
narrowedIsResError
is:
import { isResError } from "resclient";
const narrowedIsResError = (err: unknown): err is ResError => isResError(err);