license import * as ts from 'typescript' ; /**
 * The result of calling verifyTypings.
 */ export interface VerifyTypingsResult { success : boolean ; errorLog : string ; } const compilerOptions = { target : ts . ScriptTarget . ES2015 , module : ts . ModuleKind . ES2015 , moduleResolution : ts . ModuleResolutionKind . NodeJs , strict : true , noUnusedLocals : true , noUnusedParameters : true , declaration : true , lib : [ 'lib.dom.d.ts' , 'lib.esnext.d.ts' , ] , } ; const diagnosticsHost = { getNewLine : ( ) => '\n' , getCurrentDirectory : ( ) => process . cwd ( ) , getCanonicalFileName : ( fileName ) => fileName , } ; /**
 * Compile the given declaration file paths with TypeScript and return whether
 * compilation succeeded or failed, and a "pretty" formatted error log string.
 *
 * Uses a TypeScript compiler configuration suitable for web development, and
 * strict type checking.
 */ export function verifyTypings ( filePaths ) { const program = ts . createProgram ( filePaths , compilerOptions ) ; const emitResult = program . emit ( ) ; const diagnostics = ts . getPreEmitDiagnostics ( program ) . concat ( emitResult . diagnostics ) ; if ( diagnostics . length > 0 ) { return { success : false , errorLog : ts . formatDiagnosticsWithColorAndContext ( diagnostics , diagnosticsHost ) } ; } return { success : true , errorLog : '' } ; }