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

Define underscore properties as non-enumerable #58

Open
DonovanDMC opened this issue Jul 11, 2022 · 2 comments
Open

Define underscore properties as non-enumerable #58

DonovanDMC opened this issue Jul 11, 2022 · 2 comments

Comments

@DonovanDMC
Copy link

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.

@DonovanDMC
Copy link
Author

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
image

@DonovanDMC
Copy link
Author

DonovanDMC commented Jul 11, 2022

the isResError function could also be defined as isResError(o: any): o is ResError to actually narrow the type down

without:
image

with:
image

narrowedIsResError is:

import { isResError } from "resclient";
const narrowedIsResError = (err: unknown): err is ResError => isResError(err);

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

1 participant