TSCompilerAPI座談会
Leko
4月からシンガポールに住みます
/v2/
)// ...
modelChangedDebounce(sandbox, model) {
sandbox.getWorkerProcess().then((worker) =>
Promise.all([
worker.getSemanticDiagnostics(model.uri.toString()),
worker.getSyntacticDiagnostics(model.uri.toString()),
])
)
.then(([semanticDiagnostics, syntacticDiagnostics]) =>
semanticDiagnostics.concat(syntacticDiagnostics)
)
.then(diagnostics => {
// ハンドリングする
})
// ...
}
1: const port = process.env.PORT;
^^^^^^^
error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.
こういうの
1: const port = process.env.PORT;
^^^^^^^
↑Diagnosticsのstart, lengthからオレオレ生成
error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.
↑Compiler APIの一部を使用
export interface DiagnosticRelatedInformation {
category: DiagnosticCategory;
code: number;
file: SourceFile | undefined;
start: number | undefined;
length: number | undefined;
messageText: string | DiagnosticMessageChain;
}
export interface Diagnostic extends DiagnosticRelatedInformation {
/** ... */
reportsUnnecessary?: {};
source?: string;
relatedInformation?: DiagnosticRelatedInformation[];
}
messageText
といいつつstringではない messageText: string | DiagnosticMessageChain;
import type { FormatDiagnosticsHost } from 'typescript'
const formatDiagnosticHost: FormatDiagnosticsHost = { /* ... */ }
const errorMessage = ts.formatDiagnostic(d, formatDiagnosticHost)
declare namespace ts {
// ...
export interface FormatDiagnosticsHost {
getCurrentDirectory(): string;
getCanonicalFileName(fileName: string): string;
getNewLine(): string;
}
const formatDiagnosticHost: FormatDiagnosticsHost = {
getCurrentDirectory() {
return ''
},
getCanonicalFileName(fileName: string) {
return fileName
},
getNewLine() {
return '\n'
}
}