Skip to content

tsserver feature: importModuleSpecifierPreference: "non-relative" but allow siblingsΒ #55160

Open

Description

Suggestion

πŸ” Search Terms

importModuleSpecifierPreference
allow sibling

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Let auto-imports mirror:
https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-parent-imports.md
or the old:
microsoft/tslint-microsoft-contrib#778

New option, could be named anything, "non-relative-allow-sibling", "no-parent", "relative-iff-sibling", etc

πŸ“ƒ Motivating Example

re: "why this feature improves the language", this is not a language feature, but an IDE feature which happens to be handled by TypeScript repo:

readonly importModuleSpecifierPreference?: "shortest" | "project-relative" | "relative" | "non-relative";

Motivating example: When you auto-import, you want to import as ./foo if in same directory, otherwise something like @/utils/foo. shortest doesn't necessarily work since ../foo could be shorter than e.g. @/modules/feature/foo

πŸ’» Use Cases

Currently using importModuleSpecifierPreference: "non-relative" as-is.

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

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: Auto-importSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions