You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeScript 2.9 Watch API change breaking watch support in ts-loader? #24625
Apologies for raising a bug. I suspect this probably isn't a bug. (Although I suppose it may be.) I'm raising this issue because it may be a bug; but either way I could really benefit from some guidance.
I'm one of the maintainers of ts-loader. I was just doing the relevant housekeeping to cut a new release. I thought I'd switch to building ts-loader with TypeScript 2.9. However, this presents the following compile error:
src/servicesHost.ts:190:9 - error TS2322: Type '{ rootFiles: string[]; options: CompilerOptions; useCaseSensitiveFileNames: () => boolean; getNew...' is not assignable to type 'WatchHost'.
Types of property 'createProgram' are incompatible.
Type '{ (newProgram: Program, host: BuilderProgramHost, oldProgram?: BuilderProgram | undefined, config...' is not assignable to type 'CreateProgram<BuilderProgram>'.
Types of parameters 'newProgram' and 'rootNames' are incompatible.
Type 'ReadonlyArray<string> | undefined' is not assignable to type 'Program'.
Type 'undefined' is not assignable to type 'Program'.
190 const watchHost: WatchHost = {
~~~~~~~~~
The error message isn't as revealing as it might be but I think it's related to createAbstractBuilder somehow no longer aligning with createProgram.
The easiest way to see this in action is to take the ts-loader source code and amend this line from:
createProgram: compiler.createAbstractBuilderasany// TODO: Chase up with TypeScript team about API change
to:
createProgram: compiler.createAbstractBuilder
et voila! Compile error.
I've tried digging through the history of builder.ts and I've a hunch that this may be linked to the strictNullChecks switch that recently happened. Unfortunately I'm not getting enough information from the compiler to meaningful progress this. I'm drawing a blank.
Would you be able to give me some guidance please? My apologies if I'm missing something super obvious.
changed the title [-]TypeScript 2.9 Watch API change breaking Watch support in ts-loader?[/-][+]TypeScript 2.9 Watch API change breaking watch support in ts-loader?[/+]on Jun 2, 2018
importchokidarfrom'chokidar'importfsfrom'fs-extra'importpathfrom'path'import{BrowserWindow}from'electron'importtsfrom'typescript'importpkgDirfrom'pkg-dir'constROOT=pkgDir.sync(__dirname)if(!ROOT){thrownewError(`Could not find a valid project root.`)}constROOT_BUILD_GUI=path.resolve(ROOT,'build','gui')constROOT_GUI=path.resolve(ROOT,'gui')// based on: https://github.com/Microsoft/TypeScript-wiki/pull/169/constwatchGuiTS=async(): Promise<void>=>{letresolve: ()=>voidconstpromise=newPromise<void>((res)=>{resolve=res})constformatHost: ts.FormatDiagnosticsHost={getCanonicalFileName: p=>p,getCurrentDirectory: ts.sys.getCurrentDirectory,getNewLine: ()=>ts.sys.newLine}constformatDiagnostic=(diag: ts.Diagnostic)=>{returnts.formatDiagnostic(diag,formatHost).trimRight()}// @ts-ignoreconstignoreDiagnostic=(diag: ts.Diagnostic)=>{// return [6031, 6032, 6042].indexOf(diag.code) !== -1returnfalse}constreportDiagnostic=(diag: ts.Diagnostic)=>{if(!ignoreDiagnostic(diag)){console.error(formatDiagnostic(diag))}}letfirstTS6042=trueconstreportWatchStatusChanged=(diag: ts.Diagnostic)=>{if(firstTS6042&&diag.code===6042){resolve()firstTS6042=false}if(!ignoreDiagnostic(diag)){console.info(formatDiagnostic(diag))}}constsearchPath=ROOT_GUIconstconfigPath=ts.findConfigFile(searchPath,ts.sys.fileExists,'tsconfig.json')if(!configPath){thrownewError(`Could not find a valid 'tsconfig.json'.`)}consthost=ts.createWatchCompilerHost(configPath,{},ts.sys,undefined,reportDiagnostic,reportWatchStatusChanged,)ts.createWatchProgram(host)returnpromise}// ...
(I've used to use ts.createEmitAndSemanticDiagnosticsBuilderProgram instead of undefined in the call to createWatchCompilerHost and had to change that after upgrading to TS 2.9 (seems to be used by default anyway).)
Calling watchGuiTS now results in these two TS-related messages, and as there is no TS6042 message anymore, the function does not get resolved:
message TS6031: Starting compilation in watch mode...
message TS6194: Found 0 errors. Watching for file changes.
So this is where I'm stuck getting TS 2.9(.1) to work with my project ATM.
The part diag.code === 6194 && diag.messageText === 'Found 0 errors. Watching for file changes.' smells like "there is a better way to do this" but it works for now.
Activity
[-]TypeScript 2.9 Watch API change breaking Watch support in ts-loader?[/-][+]TypeScript 2.9 Watch API change breaking watch support in ts-loader?[/+]felixrabe commentedon Jun 3, 2018
I also have code that might break because of this ... bug / misunderstanding, that I based on the pull request for https://github.com/Microsoft/TypeScript-wiki/blob/master/Using-the-Compiler-API.md#writing-an-incremental-program-watcher:
(I've used to use
ts.createEmitAndSemanticDiagnosticsBuilderPrograminstead ofundefinedin the call tocreateWatchCompilerHostand had to change that after upgrading to TS 2.9 (seems to be used by default anyway).)Calling
watchGuiTSnow results in these two TS-related messages, and as there is no TS6042 message anymore, the function does not get resolved:So this is where I'm stuck getting TS 2.9(.1) to work with my project ATM.
felixrabe commentedon Jun 3, 2018
It might be that my issue (apart from the
undefinedthing that might be connected to this bug) is unrelated: I just saw that https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json is now missing TS6042 (it was present in the 2.8.3 version), and TS6194 with 0 errors might be the appropriate replacement. (Just guessing, not going on a code dig now.)felixrabe commentedon Jun 3, 2018
Ok, I ended up changing my code around
reportWatchStatusChangedto the following:The part
diag.code === 6194 && diag.messageText === 'Found 0 errors. Watching for file changes.'smells like "there is a better way to do this" but it works for now.sheetalkamat commentedon Jun 4, 2018
Felix Rabe (@felixrabe) you want to look for diagnostics code:
6193and6194since those are the replacement for Watching for file changes message.Fix the issue with createSemanticDiagnosticsBuilderProgram, createEmi…
Fix the issue with createSemanticDiagnosticsBuilderProgram, createEmi…
johnnyreilly commentedon Jun 4, 2018
Well done! 🌻
mhegazy commentedon Jun 4, 2018
fix should be in
typescript@nextlater tonight, and intypescript@2.9.2in a week.