PromiseOr<T, sync>

PromiseOr<T, sync extends "sync" | "async">: sync extends "async"
    ? T | Promise<T>
    : T

一個用於選擇同步或非同步回傳值的工具類型。

這被用作插件的回傳值,例如 CustomFunctionImporterFileImporter,以便 TypeScript 強制執行非同步插件僅傳遞給 compileAsynccompileStringAsync,而不是 compilecompileString

類型參數

  • T

  • sync extends "sync" | "async"

    如果這是 'sync',則只能是 T。如果是 'async',則可以是 TPromise<T>