Skip to content
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

Typescript watch compiles each edited file twice #51611

Closed
eladstr opened this issue Nov 21, 2022 · 4 comments Β· Fixed by #51626
Closed

Typescript watch compiles each edited file twice #51611

eladstr opened this issue Nov 21, 2022 · 4 comments Β· Fixed by #51626
Assignees
Labels
Bug A bug in TypeScript

Comments

@eladstr
Copy link

eladstr commented Nov 21, 2022

Bug Report

πŸ”Ž Search Terms

Typescript watch triggers multiple compilations

πŸ•— Version & Regression Information

This changed when moving from Typescript version 4.8.4 to 4.9.3

Reviewed: #37994

⏯ Demonstration Video

Screen.Recording.2022-11-21.at.12.46.08.mov

πŸ’» Code

package.json

{
"name": "testtsc",
"version": "1.0.0",
"description": "Test double compilation of TypeScript files",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "Elad Stern",
"license": "ISC",
"dependencies": {
"typescript": "^4.9.3"
}
}

main.ts

let a: string = "123456790123";
alert(a.slice(0, 2));

πŸ™ Actual behavior

In terminal, invoking npx and then tsc main.ts --watch, changing the source code of main.ts triggers Typescript watch to compile the file again - not once, but twice. The same took place in larger projects - double compilation of changed files, with one or two seconds in between.

πŸ™‚ Expected behavior

Once a source code file has been changed, it should compile only once by tsc watch, not twice.

@eladstr
Copy link
Author

eladstr commented Nov 21, 2022

@eladstr eladstr closed this as completed Nov 21, 2022
@eladstr eladstr reopened this Nov 21, 2022
@sheetalkamat
Copy link
Member

please post log with tsc --watch main.ts --extendedDiagnostics even though it looks like it has compiled twice the actual transformation should happen only once. It looks like on windows (which is where i tested) the file change event was generated twice which is why this behaviour.

@eladstr
Copy link
Author

eladstr commented Nov 22, 2022

terminal output with --extendedDiagnostics:

sh-3.2$ tsc main.ts --watch --extendedDiagnostics
[10:18:14 AM] Starting compilation in watch mode...

Current directory: /Users/elads/Projects/testtsc CaseSensitiveFileNames: false
Synchronizing program
CreatingProgramWith::
roots: ["main.ts"]
options: {"watch":true,"extendedDiagnostics":true}
FileWatcher:: Added:: WatchInfo: main.ts 250 undefined Source file
FileWatcher:: Added:: WatchInfo: /Users/elads/Projects/testtsc/node_modules/typescript/lib/lib.d.ts 250 undefined Source file
FileWatcher:: Added:: WatchInfo: /Users/elads/Projects/testtsc/node_modules/typescript/lib/lib.es5.d.ts 250 undefined Source file
FileWatcher:: Added:: WatchInfo: /Users/elads/Projects/testtsc/node_modules/typescript/lib/lib.dom.d.ts 250 undefined Source file
FileWatcher:: Added:: WatchInfo: /Users/elads/Projects/testtsc/node_modules/typescript/lib/lib.webworker.importscripts.d.ts 250 undefined Source file
FileWatcher:: Added:: WatchInfo: /Users/elads/Projects/testtsc/node_modules/typescript/lib/lib.scripthost.d.ts 250 undefined Source file
DirectoryWatcher:: Added:: WatchInfo: /Users/elads/Projects/testtsc/node_modules/@types 1 undefined Type roots
Elapsed:: 0.2658340334892273ms DirectoryWatcher:: Added:: WatchInfo: /Users/elads/Projects/testtsc/node_modules/@types 1 undefined Type roots
[10:18:14 AM] Found 0 errors. Watching for file changes.

Files: 6
Lines of Library: 23413
Lines of Definitions: 0
Lines of TypeScript: 2
Lines of JavaScript: 0
Lines of JSON: 0
Lines of Other: 0
Identifiers: 39746
Symbols: 27134
Types: 9517
Instantiations: 2630
Memory used: 72906K
Assignability cache size: 3405
Identity cache size: 0
Subtype cache size: 0
Strict subtype cache size: 0
I/O Read time: 0.00s
Parse time: 0.12s
Program time: 0.13s
Bind time: 0.05s
Check time: 0.28s
printTime time: 0.01s
Emit time: 0.01s
transformTime time: 0.00s
commentTime time: 0.00s
I/O Write time: 0.00s
Total time: 0.47s
FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Scheduling update
Elapsed:: 0.469124972820282ms FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Synchronizing program
[10:18:24 AM] File change detected. Starting incremental compilation...

CreatingProgramWith::
roots: ["main.ts"]
options: {"watch":true,"extendedDiagnostics":true}
[10:18:24 AM] Found 0 errors. Watching for file changes.

Files: 6
Lines of Library: 23413
Lines of Definitions: 0
Lines of TypeScript: 2
Lines of JavaScript: 0
Lines of JSON: 0
Lines of Other: 0
Identifiers: 39746
Symbols: 27134
Types: 9517
Instantiations: 2630
Memory used: 91604K
Assignability cache size: 3405
Identity cache size: 0
Subtype cache size: 0
Strict subtype cache size: 0
I/O Read time: 0.00s
Parse time: 0.00s
Program time: 0.00s
Bind time: 0.00s
Check time: 0.26s
transformTime time: 0.01s
commentTime time: 0.00s
printTime time: 0.01s
Emit time: 0.01s
I/O Write time: 0.00s
Total time: 0.27s
FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Scheduling update
Elapsed:: 0.15825003385543823ms FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Synchronizing program
[10:18:25 AM] File change detected. Starting incremental compilation...

CreatingProgramWith::
roots: ["main.ts"]
options: {"watch":true,"extendedDiagnostics":true}
[10:18:25 AM] Found 0 errors. Watching for file changes.

Files: 6
Lines of Library: 23413
Lines of Definitions: 0
Lines of TypeScript: 2
Lines of JavaScript: 0
Lines of JSON: 0
Lines of Other: 0
Identifiers: 39746
Symbols: 23958
Types: 82
Instantiations: 0
Memory used: 78447K
Assignability cache size: 0
Identity cache size: 0
Subtype cache size: 0
Strict subtype cache size: 0
I/O Read time: 0.00s
Parse time: 0.00s
Program time: 0.00s
Bind time: 0.00s
Total time: 0.00s

thanks

@sshrshnv
Copy link

sshrshnv commented Sep 8, 2024

The same error in Typescript version 5.5.4 (macOS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants