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

Should throw if falsey key value exists #1

Closed
donavon opened this issue Feb 21, 2018 · 3 comments
Closed

Should throw if falsey key value exists #1

donavon opened this issue Feb 21, 2018 · 3 comments

Comments

@donavon
Copy link

donavon commented Feb 21, 2018

In your example, if foo.d is already set to say 5, it throws. I would expect that. However, if it is 0 (or anything falsey), it paves over the falsey value.

{a: 1, b: 2, d: 0}
//=> { a:1, b:2, d:{ e:{ f:'hello' } } };

A possible fix is:

x = o[keys[i]] === undefined ? {} : o[keys[i]];
@lukeed
Copy link
Owner

lukeed commented Feb 21, 2018

Ah, right, good catch~! I'll fix this, but we should also be paving on null value too.

Slightly unrelated, but thoughts about not throwing if a value exists? Instead, would silently break & exit.

@lukeed lukeed closed this as completed in f1b36b8 Feb 21, 2018
@donavon
Copy link
Author

donavon commented Feb 21, 2018

I wouldn't pave over a null as it is an actual value.

I'm a big fan of throwing when there is an exception. Hiding/masking the problem will make it harder to track down the root cause.

Actually, you might want to use this instead:

x = keys[i] in o ? o[keys[i]] : {};

@lukeed
Copy link
Owner

lukeed commented Feb 21, 2018

That'd throw immediately for anything that isn't already an object, including undefineds 😆 That's probably what you want, except for the latter.

lukeed added a commit that referenced this issue Oct 25, 2023
* fix: TS .d.ts resolution (#1)

There are types at '/node_modules/dset/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'dset' library may need to update its package.json or typings.ts(7016)

* Update package.json (#2)

* Simplified package exports

* Updated back to original repo

* Update package.json

---------

Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
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

2 participants