-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript 2.9 Watch API change breaking watch support in ts-loader? #24625
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
Comments
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: import chokidar from 'chokidar'
import fs from 'fs-extra'
import path from 'path'
import { BrowserWindow } from 'electron'
import ts from 'typescript'
import pkgDir from 'pkg-dir'
const ROOT = pkgDir.sync(__dirname)
if (!ROOT) {
throw new Error(`Could not find a valid project root.`)
}
const ROOT_BUILD_GUI = path.resolve(ROOT, 'build', 'gui')
const ROOT_GUI = path.resolve(ROOT, 'gui')
// based on: https://github.com/Microsoft/TypeScript-wiki/pull/169/
const watchGuiTS = async (): Promise<void> => {
let resolve: () => void
const promise = new Promise<void>((res) => { resolve = res })
const formatHost: ts.FormatDiagnosticsHost = {
getCanonicalFileName: p => p,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine
}
const formatDiagnostic = (diag: ts.Diagnostic) => {
return ts.formatDiagnostic(diag, formatHost).trimRight()
}
// @ts-ignore
const ignoreDiagnostic = (diag: ts.Diagnostic) => {
// return [6031, 6032, 6042].indexOf(diag.code) !== -1
return false
}
const reportDiagnostic = (diag: ts.Diagnostic) => {
if (!ignoreDiagnostic(diag)) {
console.error(formatDiagnostic(diag))
}
}
let firstTS6042 = true
const reportWatchStatusChanged = (diag: ts.Diagnostic) => {
if (firstTS6042 && diag.code === 6042) {
resolve()
firstTS6042 = false
}
if (!ignoreDiagnostic(diag)) {
console.info(formatDiagnostic(diag))
}
}
const searchPath = ROOT_GUI
const configPath = ts.findConfigFile(searchPath, ts.sys.fileExists, 'tsconfig.json')
if (!configPath) {
throw new Error(`Could not find a valid 'tsconfig.json'.`)
}
const host = ts.createWatchCompilerHost(configPath, {}, ts.sys,
undefined,
reportDiagnostic,
reportWatchStatusChanged,
)
ts.createWatchProgram(host)
return promise
}
// ... (I've used to use Calling
So this is where I'm stuck getting TS 2.9(.1) to work with my project ATM. |
It might be that my issue (apart from the |
Ok, I ended up changing my code around const formatDiagnostic = (diag: ts.Diagnostic) => {
return ts.formatDiagnostic(diag, formatHost).trimRight()
}
const ignoreDiagnostic = (diag: ts.Diagnostic) => {
return [6031, 6032].indexOf(diag.code) !== -1
}
const reportDiagnostic = (diag: ts.Diagnostic) => {
if (!ignoreDiagnostic(diag)) {
console.error(formatDiagnostic(diag))
}
}
let firstCompilationDone = false
const isCompilationDone = (diag: ts.Diagnostic) => {
return diag.code === 6194 && diag.messageText === 'Found 0 errors. Watching for file changes.'
}
const reportWatchStatusChanged = (diag: ts.Diagnostic) => {
if (!firstCompilationDone && isCompilationDone(diag)) {
resolve()
firstCompilationDone = true
}
if (!ignoreDiagnostic(diag)) {
console.info(formatDiagnostic(diag))
}
} The part |
@felixrabe you want to look for diagnostics code: |
…tAndSemanticDiagnosticsBuilderProgram and createAbstractBuilder not assignable to CreateProgram<T> Fixes #24625
…tAndSemanticDiagnosticsBuilderProgram and createAbstractBuilder not assignable to CreateProgram<T> Fixes #24625
Well done! 🌻 |
fix should be in |
Hey everybody! (and in particular @sheetalkamat and @Andy-MS !)
TypeScript Version: 2.9.1
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:
The error message isn't as revealing as it might be but I think it's related to
createAbstractBuilder
somehow no longer aligning withcreateProgram
.The easiest way to see this in action is to take the ts-loader source code and amend this line from:
to:
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 thestrictNullChecks
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.
The text was updated successfully, but these errors were encountered: