Named Imports vs Object Destructuring

preview_player
Показать описание

I'll show you why/how they're different and why that matters.
Рекомендации по теме
Комментарии
Автор

Super interesting that it's a runtime vs. compile time concern... I can definitely see how allowing the destructuring syntax in imports could be misleading. Thx for the explanation 🥳

HarrySolovay
Автор

Another reason the destructuring isn’t allowed is that you’re exporting the variables, not their values. For example, if you export a `let`-declared variable, it’s immutable when imported, but the original module can still change it and the value will update in all the dependents immediately. If you could destructure an imported value in the import statement, not only would the engine have to run the getter (if any) whenever the variable is accessed, if the original export is set to null or undefined at some point in the future, the destructuring would somehow have to become retroactively illegal.

jed_fox
Автор


I usually check “hide type keys” and “hide location data” since the type is shown before the `{` and the location data isn’t too useful for humans. These remove those keys from the displayed output so you can see more on the screen.

jed_fox