if type errors
edemaine opened this issue · comments
I was trying to write a proper type for our compile function (once it becomes async
):
export function compile<T extends CompileOptions>(src: string, options?: T): Promise<
if T extends { ast: true }
CivetAST
else
if T extends { sourceMap: true }
code: string
sourceMap: SourceMap
else
string
>
The current compilation has multiple bugs:
export function compile<T extends CompileOptions>(src: string, options?: T): Promise<
(T extends { ast: true }?
CivetAST
:
(T extends { sourceMap: true }?
{code: string}:never)),
{sourceMap: SourceMap},
else,
string
>
It's missing two close parentheses, and it says else,
instead of the second :
.
Also, it would be nice to be able to write else if
here.
Related, it's not possible to have a newline after :
in a ?:
type:
type CompileOutput<T extends CompileOptions> =
T extends { ast: true } ? CivetAST :
T extends { sourceMap: true } ? {
code: string,
sourceMap: SourceMap,
} : string