Skip to content

Preference for including file extension on auto imports #24779

Closed
microsoft/vscode
#90405

Description

@mjbvz

Search Terms

  • Auto imports
  • Preferences
  • File extensions

Suggestion

From microsoft/vscode#51259

Add a preference to include file extensions on auto import paths.

Use Cases

File extensions are required when working with browsers.

Examples

a.js:

export const abc = 123;

b.js

abc|

Trigger auto import on abc in b.js to get:

import { abc } from './a.js'

abc

Activity

  1. mhegazy commented on Jun 8, 2018

    @mhegazy
    Contributor

    PRs welcomed for adding support of file extension preference

  2. added
    CommittedThe team has roadmapped this issue
    and removed on Feb 5, 2020
  3. andrewbranch commented on Feb 10, 2020

    @andrewbranch
    Member

    This has actually existed in TS since #26177, but was never added to typescript-language-features. I just tried it and confirmed it works. From conversation in #28288, though, it sounds like we should maybe consider setting .js endings as the default for JS projects? Matt Bierner (@mjbvz) Daniel Rosenwasser (@DanielRosenwasser) thoughts? (Edit: Actually, I think this would still be a surprising default for most JS users—I don’t think it’s common in Node, and most frontend users still use a bundler.)

  4. wsmd commented on May 6, 2020

    @wsmd

    Question related to microsoft/vscode#90405 - Is there an existing configuration that can achieve the same behavior for autosuggest when typing the import statement manually?

    For example:

    {
      "javascript.preferences.importModuleSpecifierEnding": "js",
    }
    import { someFunction } from './|';
                                    ^ when picking a file from suggestions here,
                                      the file extension seems to always be omitted
  5. andrewbranch commented on May 6, 2020

    @andrewbranch
    Member

    I can’t immediately think of a reason why we shouldn’t respect that same setting for module specifier completions. Waseem Dahman (@wsmd) would you mind opening a new bug for this?

  6. wsmd commented on May 6, 2020

    @wsmd

    Thanks Andrew Branch (@andrewbranch)! Will do! I think it would be nice to have importModuleSpecifierEnding applies for both auto-imports and manual import suggestions 👍

    Reported here https://github.com/microsoft/vscode/issues/97106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CommittedThe team has roadmapped this issueFix AvailableA PR has been opened for this issueSuggestionAn idea for TypeScriptVS Code PriorityCritical issues that VS Code needs fixed in the current TypeScript milestoneVS Code TrackedThere is a VS Code equivalent to this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions