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

CodeFix to import entire module into single variable #13295

Closed
normalser opened this issue Jan 5, 2017 · 9 comments
Closed

CodeFix to import entire module into single variable #13295

normalser opened this issue Jan 5, 2017 · 9 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Domain: Quick Fixes Editor-provided fixes, often called code actions. Suggestion An idea for TypeScript

Comments

@normalser
Copy link

Not sure if this would be possible but it would be nice if one could import entire module into single variable.

For example CodeFix on bluebird or on mapSeries

image

would offer import * as bluebird from 'bluebird'

@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions. Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Jan 5, 2017
@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented Jan 5, 2017

it would require a long list of configurable aliases #13270 just like for #13084:

"codefixes": {
    "import": {
        "aliases": {
            "bluebird": "../../bluebrid.js"
        }
     }
 }

@aluanhaddad
Copy link
Contributor

This comment seems relevant leebyron/ecmascript-more-export-from#11 (comment) Specifically the performance characteristics of this pattern are perhaps significant.

@ChiriVulpes
Copy link

I wonder if this could be fixed relatively easily by piggybacking on the exports from the module. For instance, in the screenshot that @normalser provided, he requests a specific property of the bluebird file. If you take off the bluebird part, and just do mapSeries, it should already offer you to import that as import { mapSeries } from "bluebird";
As a result, the codefixer could see bluebird.mapSeries, see that bluebird is undefined, but see you're trying to get something specific from it, look for that specific thing that you're getting (in this case, mapSeries), then suggest importing everything into the bluebird variable you're using. import * as bluebird from "bluebird";

@mhegazy
Copy link
Contributor

mhegazy commented Jan 12, 2018

This should not be needed with the auto-import feature.
animation

@mhegazy mhegazy closed this as completed Jan 12, 2018
@ChiriVulpes
Copy link

See the OP. The request is to import an entire module into one variable, not to import one export of a module.

@mhegazy mhegazy reopened this Jan 12, 2018
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Nov 12, 2018

We now have a refactoring to go between the two:

namespacetonamedimports

Not quite what you want but it's close.

@ChiriVulpes
Copy link

That'll be nice for refactoring. I think this issue is still useful for writing the code, as that code fix will be more of a workaround since it takes more steps.

I can imagine being used to using the namespace import in one file and then moving to another and starting to do it that way, but it's not imported yet. There's no code fix for that, so then you have to first import the child, then change it to a namespace import at the top of the file. I could also imagine copying code that uses the namespace style and having to do the workaround for that as well.

As a result I still think this issue is worth keeping, even if it's implemented a long way down the road.

@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Mar 11, 2024
@RyanCavanaugh
Copy link
Member

This doesn't seem to be a common request.

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
@DanielRosenwasser
Copy link
Member

Was this a duplicate of #23830?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Domain: Quick Fixes Editor-provided fixes, often called code actions. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants