Let’s take a simple example:
type filePath = Opaque<...>;
function isFile(path: string, stats: Stats): path is filePath {
return stats.isFile();
}
Works great. Now I’m trying to make that function async:
function isFile(path: string): Promise<path is filePath> {
const stats = await stat(path);
return stat.isFile();
}
However typescript doesn’t even like the syntax there and absolutely chokes on Promise<path is filePath>
. Is there a way to get a type predicate into a promise?
obligatory ts playground link
New contributor
nobody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.