Comprehensive error reporting system with multiple reporter types for different output formats and integration scenarios. Reporters handle TypeScript compilation errors, warnings, and completion results.
Core interface for handling TypeScript compilation errors and results.
interface Reporter {
/**
* Handle compilation errors
* @param error - TypeScript error with diagnostic information
* @param typescript - TypeScript instance for error processing
*/
error?: (error: TypeScriptError, typescript: typeof ts) => void;
/**
* Handle compilation completion
* @param results - Compilation results with error counts
*/
finish?: (results: CompilationResult) => void;
}Reporter that suppresses all error output, useful for silent builds or when handling errors programmatically.
/**
* Create a reporter that suppresses all error output
* @returns Reporter that produces no console output
*/
function nullReporter(): Reporter;Usage Examples:
import * as gulp from 'gulp';
import * as ts from 'gulp-typescript';
// Silent compilation without error output
gulp.task('compile-silent', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
noImplicitAny: true
}, ts.reporter.nullReporter()))
.pipe(gulp.dest('dist'));
});
// Use with project
const tsProject = ts.createProject('tsconfig.json');
gulp.task('compile-project-silent', () => {
return gulp.src('src/**/*.ts')
.pipe(tsProject(ts.reporter.nullReporter()))
.pipe(gulp.dest('dist'));
});Standard console reporter for basic error reporting with file names and error messages.
/**
* Create the default console reporter for basic error output
* @returns Reporter that logs basic error information to console
*/
function defaultReporter(): Reporter;Usage Examples:
import * as gulp from 'gulp';
import * as ts from 'gulp-typescript';
// Use default reporter explicitly
gulp.task('compile-default', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
strict: true
}, ts.reporter.defaultReporter()))
.pipe(gulp.dest('dist'));
});
// Default reporter is used automatically if none specified
gulp.task('compile-auto-default', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
strict: true
}))
.pipe(gulp.dest('dist'));
});Extended version of the default reporter with additional context information, supporting IntelliJ link functionality and file watcher error highlighting.
/**
* Create an extended console reporter with additional context
* Provides IntelliJ link functionality and file watcher error highlighting
* @returns Reporter with enhanced error information
*/
function longReporter(): Reporter;Usage Examples:
import * as gulp from 'gulp';
import * as ts from 'gulp-typescript';
// Use long reporter for detailed error information
gulp.task('compile-detailed', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
strict: true,
noUnusedLocals: true
}, ts.reporter.longReporter()))
.pipe(gulp.dest('dist'));
});
// Ideal for development with IDE integration
const devProject = ts.createProject('tsconfig.json');
gulp.task('dev-compile', () => {
return gulp.src('src/**/*.ts')
.pipe(devProject(ts.reporter.longReporter()))
.pipe(gulp.dest('dist'));
});Comprehensive reporter that shows full error messages with source code context for detailed debugging.
/**
* Create a comprehensive reporter with full error messages and source context
* @param fullFilename - Whether to show full file paths (default: false)
* @returns Reporter with complete error information and source context
*/
function fullReporter(fullFilename?: boolean): Reporter;Usage Examples:
import * as gulp from 'gulp';
import * as ts from 'gulp-typescript';
// Full reporter with relative file names
gulp.task('compile-full', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
strict: true
}, ts.reporter.fullReporter()))
.pipe(gulp.dest('dist'));
});
// Full reporter with absolute file paths
gulp.task('compile-full-absolute', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
strict: true
}, ts.reporter.fullReporter(true)))
.pipe(gulp.dest('dist'));
});
// Ideal for CI/CD environments with detailed logging
const ciProject = ts.createProject('tsconfig.json');
gulp.task('ci-compile', () => {
return gulp.src('src/**/*.ts')
.pipe(ciProject(ts.reporter.fullReporter(true)))
.pipe(gulp.dest('dist'));
});Utility functions for working with compilation results and error counting.
/**
* Count total errors in compilation results
* @param results - Compilation results to analyze
* @returns Total number of errors across all categories
*/
function countErrors(results: CompilationResult): number;
/**
* Create an empty compilation result
* @param noEmit - Whether emit is disabled
* @returns Empty compilation result with zero error counts
*/
function emptyCompilationResult(noEmit: boolean): CompilationResult;Usage Examples:
import * as ts from 'gulp-typescript';
// Custom reporter using error utilities
function customReporter(): ts.reporter.Reporter {
return {
error: (error, typescript) => {
console.log(`Error in ${error.relativeFilename}: ${error.message}`);
},
finish: (results) => {
const totalErrors = ts.reporter.countErrors(results);
if (totalErrors > 0) {
console.log(`Compilation failed with ${totalErrors} errors`);
} else {
console.log('Compilation successful');
}
}
};
}
gulp.task('compile-custom-reporter', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
strict: true
}, customReporter()))
.pipe(gulp.dest('dist'));
});interface TypeScriptError extends Error {
/** Full path to the file containing the error */
fullFilename?: string;
/** Relative path to the file containing the error */
relativeFilename?: string;
/** Gulp vinyl file object */
file?: VinylFile;
/** TypeScript source file */
tsFile?: ts.SourceFile;
/** TypeScript diagnostic information */
diagnostic: ts.Diagnostic;
/** Error start position information */
startPosition?: {
position: number;
line: number;
character: number;
};
/** Error end position information */
endPosition?: {
position: number;
line: number;
character: number;
};
}
interface CompilationResult {
/** Transpile errors (only used with isolatedModules) */
transpileErrors: number;
/** Compiler options errors */
optionsErrors: number;
/** Syntax errors in source code */
syntaxErrors: number;
/** Global compilation errors */
globalErrors: number;
/** Semantic analysis errors */
semanticErrors: number;
/** Declaration file generation errors */
declarationErrors: number;
/** File emission errors */
emitErrors: number;
/** Whether emit was disabled */
noEmit: boolean;
/** Whether emit was skipped due to errors */
emitSkipped: boolean;
}
interface VinylFile {
contents: Buffer | NodeJS.ReadableStream | null;
cwd: string;
base: string;
path: string;
dirname: string;
basename: string;
stem: string;
extname: string;
sourceMap?: any;
}