Skip to content

Update imports on file move rewrites ./index to '.' #26028

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

Closed
mjbvz opened this issue Jul 27, 2018 · 4 comments
Closed

Update imports on file move rewrites ./index to '.' #26028

mjbvz opened this issue Jul 27, 2018 · 4 comments
Labels
Domain: Quick Info e.g. hover text, tool-tips, and tooltips. Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jul 27, 2018

From microsoft/vscode#54981 (comment)

TypeScript Version: 3.1.0-dev.20180726

Search Terms:

  • update imports
  • getEditsForFileRename

Code
For a project

index.ts

export const foo = 123

foo.ts

import { foo } from './index';
  1. In VScode, Rename foo.ts to bar.ts
  2. Confirm that you want to update import paths

Expected behavior:
No edits returned from getEditsForFileRename

Actual behavior:
An edit is returned that rewrites foo.ts to:

import { foo } from '.';
@ghost
Copy link

ghost commented Jul 28, 2018

We could add this as a new UserPreferences property: readonly importIndexPreference: "omitIndex" | "includeIndex";.

@mhegazy mhegazy added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Jul 28, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jul 28, 2018

What should the default be?

@mhegazy mhegazy added the Domain: Quick Info e.g. hover text, tool-tips, and tooltips. label Jul 28, 2018
@mjbvz
Copy link
Contributor Author

mjbvz commented Jul 28, 2018

My expectation as a user is that we don't touch the import in this case. If it's './index' leave it as './index' and if its '.' leave it as '.'

@mhegazy mhegazy assigned ghost Jul 28, 2018
@mhegazy mhegazy added this to the TypeScript 3.1 milestone Jul 28, 2018
@mhegazy mhegazy removed the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Jul 28, 2018
@jdforsythe
Copy link

jdforsythe commented Jul 30, 2018

@Andy-MS @mhegazy I think it should be: readonly importIndexPreference: "omitIndex" | "includeIndex" | "noChange";

where "noChange" is the default. Then users could opt in to always or never include index, but the default is to not change existing imports.

Normally we omit it, but for a particular module we only allow importing through the index file (due to some registration that happens) so the lint rule requires index to be present for this particular import.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Quick Info e.g. hover text, tool-tips, and tooltips. Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants