Support for type destructuring
See original GitHub issueTypeScript Version: 2.1.4
Code
import { MyNamespace } from 'my-package';
// importing Class objects:
const { NavLink, NavGroup } = MyNamespace; // VALID
// if we want the types as well:
type { NavLink, NavGroup } = MyNamespace; // NOT VALID
// So we have to go manual:
type NavLink = MyNamespace.NavLink; // VALID
type NavGroup = MyNamespace.NavLink; // VALID
Expected behavior: Being able to use destructuring for types same as we use for objects.
Actual behavior: Can only use destructuring for objects.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:90
- Comments:25 (5 by maintainers)
Top Results From Across the Web
Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >typescript - Types in object destructuring - Stack Overflow
Types don't need to be specified for object properties because they are inferred from destructured object. Considering that bar was typed properly, foo...
Read more >Handling Safe Destructuring in TypeScript - Kamranicus
Supporting partial objects This does two things: it allows the safe destructuring without compiler errors and, it tells the reader to expect to ......
Read more >Destructuring - TypeScript Deep Dive - Gitbook
Without the awesome structuring support built into JavaScript, creating new objects on the fly would indeed be very cumbersome. Destructuring brings the ...
Read more >Typescript Destructure - Visual Studio Marketplace
This TypeScript Language Service Plugin provides a set of source actions that simplify object destructuring as well as folding specific ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If this is supported, it seems like it should work for the
import
statement as well so that one may acquire both the type and value space meanings if desired.@shellscape pretty much everything TypeScript could possibly ever do was suggested at one point within the first two years of its release, which was about 10 years ago. Needless to say, in that timeframe, we have not done every possible thing, nor could/should we have. C++ is nearing 40 years old at this point and is still adding new features. You’ll need to readjust expectations around how fast a language can responsibly add features, unfortunately.