question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for type destructuring

See original GitHub issue

TypeScript 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:open
  • Created 7 years ago
  • Reactions:90
  • Comments:25 (5 by maintainers)

github_iconTop GitHub Comments

23reactions
aluanhaddadcommented, Dec 23, 2016

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.

import { NavLink, NavGroup } = MyNamespace; // NOT VALID
14reactions
RyanCavanaughcommented, Jan 20, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found