-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Destructuring a store object retuns the whole store if the property does not exist #4170
Comments
Interesting. The problem is that here where we're defining the |
@Conduitry in which conditions svelte/src/compiler/compile/render_dom/Renderer.ts Lines 151 to 198 in a8b306f
But anyway, maybe we could check if |
The original REPL that reproduces this error is one where |
I see 3 ways to solve this: 1. Using 2. Creating two 3. Passing a single object though !!Object.keys({ i: 1, ret: { value: 'test' }, value: undefined }).find(e => e === 'value') // true
!!Object.keys({ i: 1, ret: { value: 'test' } }).find(e => e === 'value') // false |
I haven't tried this yet, but what seems like it might be a good solution is to make |
I guess you mean |
@AnatoleLucet The way the method is currently set up, if value is undefined then it is made to equal ret, which means if value was explicitly undefined, there is no way of knowing (since it is then set to ret). If changed around as @Conduitry proposed, value could be explicitly undefined. I also don't think it would require any rewriting for the compiler, since it would work roughly the same as it did previously, with the exception of being able to handle explicitly undefined values. |
Fixed in 3.17.0 - https://svelte.dev/repl/52333798bbea4d1b8bb5e249be1cca18?version=3.17.0 |
Thanks ! And by the way, congratulation for this great framework :) |
Describe the bug
When destructuring a store, the whole store object is returned if the property does not exist:
$: ({shouldBeUndefined} = $store);
It works if used with an existing property, i.e.:
$: ({existingProperty, shouldBeUndefined} = $store);
To Reproduce
You can find the REPL here
Information about your Svelte project:
Severity
Annoying
Thanks!
The text was updated successfully, but these errors were encountered: