第二个论点
emit()
是
writeFile?: WriteFileCallback
. 您可以尝试使用它,并以您需要的任何方式自己编写文件:
program.emit(undefined, yourOwnWriteFileFunction);
此外,根据评论和规范,
ts.createProgram()
接受的自定义实现
CompilerHost
也可以覆盖
writeFile
:
export interface CompilerHost extends ModuleResolutionHost {
....
writeFile: WriteFileCallback;
Relevant part of
Program
interface
export interface Program extends ScriptReferenceHost {
/**
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then
* the JavaScript and declaration files will be produced for all the files in this program.
* If targetSourceFile is specified, then only the JavaScript and declaration for that
* specific file will be generated.
*
* If writeFile is not specified then the writeFile callback from the compiler host will be
* used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter
* will be invoked when writing the JavaScript and declaration files.
*/
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult;
请注意,API的这些部分没有记录在typescript wiki上,因此如果您决定使用它们,应该密切关注
breaking API changes page
.