Skip to content

tsc --build --clean unexpectedly deletes JavaScript files when noEmit is enabled if outDir is not set #43116

@RA80533

Description

@RA80533

Bug Report

🔎 Search Terms

--build, build, --clean, clean, composite, noEmit, outDir

🕗 Version & Regression Information

  • Version 4.2.3
  • Version 4.3.0-dev.20210306 via typescript@next

💻 Code

$ touch index.js
{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "composite": true,
    "noEmit": true
  },
  "files": [
    "index.js"
  ]
}
  • Although checkJs implies allowJs, both were included in the snippet for the purpose of clarity.
  • While the bug occurs in non-composite projects, the composite property was included in the snippet to demonstrate a likely use case wherein the bug occurs.
Running the compiler with --build

$ tsc --build
$ git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        tsconfig.tsbuildinfo

nothing added to commit but untracked files present (use "git add" to track)

Running the compiler with --build --clean

$ tsc --build --clean
$ git status
On branch main
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    index.js

no changes added to commit (use "git add" and/or "git commit -a")

🙁 Actual behavior

  • index.js is removed
  • tsconfig.tsbuildinfo is removed

🙂 Expected behavior

  • tsconfig.tsbuildinfo is removed

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions