Description
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:
microsoft/vscode#51366
#23573
#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.