镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

"tsc --project tsconfig.json --incremental" doesn't clean files from output folder. #36648

Description

@trusktr

TypeScript Version: 3.7.5

Search Terms:

tsc incremental doesn't clean old files

Code

N/A

Expected behavior:

When, for example, refactoring by renaming a file (and VS Code updates all import statements, etc), then the outputDir should not contain the old file.

Actual behavior:

The output directory contains old unused files.

Prior to trying incremental builds (today for the first time) I was simply doing rm -rf dist/ to "clean" it first. This doesn't work with incremental builds (#30602).

I tried running tsc --build --clean and tsc --build ./tsconfig.json --clean but those don't do anything, old files still remain in the output folder.

Note, I have a single tsconfig.json at the root of my project, and compile all my source code into a single output directory all at once with a single tsc command. I'm not "composing projects".

Playground Link:

N/A

Related Issues:

Activity

  1. sheetalkamat commented on Feb 5, 2020

    @sheetalkamat
    Member

    tsc --build --clean will only clean the files that are the outputs from current program so if you changed the name of the file or there exists some old file that's not part of the project' its output wont be deleted. For now this is by design and we do not track files that aren't part of compilation

  2. typescript-bot commented on Feb 11, 2020

    @typescript-bot
    Contributor

    This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

  3. leotm commented on Mar 22, 2020

    @leotm

    It's because of VS Code's integrated Git support.

    A right-click Rename does a git mv (git rm --cached + mv + git add).

    Our TypeScript compiler only sees working directory changes, i.e. mv changes in our outDir, whereas git add is where Git will automatically detect the move/rename.

    Both being by Microsoft, it would be nice to see relevant Git support in our compiler presumably before looking at other VCS's.

  4. trusktr commented on Aug 4, 2020

    @trusktr
    ContributorAuthor

    For now this is by design and we do not track files that aren't part of compilation

    Makes sense, and this makes it possible to output JS and declaration files as siblings to the input TS files, which is a valid use case.

    Maybe there can be an option for it though? f.e. cleanNonOutputFilesFromProjectOutput: true or some descriptive name like that.

  5. croraf commented on Sep 13, 2020

    @croraf

    This happens not only in --incremental mode.

  6. trusktr commented on Nov 3, 2020

    @trusktr
    ContributorAuthor

    Sheetal Nandi (@sheetalkamat) I suppose someone somewhere if going to accidentally publish files they didn't mean to publish.

  7. aweebit commented on Feb 27, 2025

    @aweebit

    Sheetal Nandi (@sheetalkamat) Ryan Cavanaugh (@RyanCavanaugh) can't the .tsbuildinfo file be utilized to only delete output files corresponding to the source files from the previous build that are no longer present? Seems like a pretty reasonable and straightforward use of .tsbuildinfo.

    Not having this automatic cleanup has at least two pretty bad implications:

    It looks like using a third-party tool like Google's Wireit (see its dedicated TypeScript recipe) is right now the only viable way to avoid these problems.

  8. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions