TypeScript: "rename file" and "move to new file" refactors do not work when using `files`

TypeScript Version: 2.9.1

Search Terms: files “move to new file” “rename file”

Code

// tsconfig.json
{
  "files": ["./src/index.ts"]
}
// ./src/index.ts
import foo from './other';
// ./src/other.ts
export default {}

const bar = {};

Expected behavior:

  • When renaming the file ./src/other.ts, I expect TypeScript/VSCode to prompt me to update the import in ./src/index.ts.
  • When selecting bar in ./src/other.ts, TypeScript/VSCode offers to move this to a new file. When actioning this, I expect this to work.

(TypeScript knows that ./src/other.ts is in the project because it is part of the traced dependency graph from the entry file ./src/index.ts.)

Actual behavior:

  • When renaming the file ./src/other.ts, there is no prompt to update the import.
  • When selecting bar in ./src/other.ts, TypeScript/VSCode offers to move this to a new file. When actioning this, nothing happens.

Playground Link:

Related Issues: https://github.com/Microsoft/vscode/issues/51366 https://github.com/Microsoft/TypeScript/pull/23573 https://github.com/Microsoft/TypeScript/pull/23726


A known workaround is to use the include option instead of files. However, I am curious why this is necessary. I prefer to list the entry file and let TypeScript work the rest out. This is especially helpful when a folder has a combination of source and test files—TypeScript automatically knows not to include the test files because they are not part of the dependency graph.

If there is a good reason why these commands/refactors can’t work with files, could we make the experience clearer? Why is the “move to new file” command suggested in VSCode when it leads to nothing? If so, perhaps this is an issue for VSCode.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 40 (29 by maintainers)

Most upvoted comments

@rosieks move to file isn’t yet supported in Visual Studio 15.8, so unfortunately even a new build of TypeScript won’t help you in this case. We’re working on adding VS support for this soon.