export async function getDeclarations ( vfs ) { const ts = await import ( 'typescript' ) ; const inputFiles = [ ... vfs . keys ( ) ] ; const compilerOptions = { allowJs : true , declaration : true , incremental : true , skipLibCheck : true , emitDeclarationOnly : true } ; const tsHost = ts . createCompilerHost ! ( compilerOptions ) ; tsHost . writeFile = ( fileName , declaration ) => { vfs . set ( fileName , declaration ) ; } ; const _readFile = tsHost . readFile ; tsHost . readFile = ( filename ) => { if ( vfs . has ( filename ) ) { return vfs . get ( filename ) ; } return _readFile ( filename ) ; } ; const program = ts . createProgram ! ( inputFiles , compilerOptions , tsHost ) ; await program . emit ( ) ; const output = { } ; for ( const filename of inputFiles ) { const dtsFilename = filename . replace ( /\.(ts|js)$/ , '.d.ts' ) ; output [ filename ] = vfs . get ( dtsFilename ) || '' ; } return output ; }