DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.33k stars 28 forks source link

Fix if types #1298

Closed edemaine closed 3 days ago

edemaine commented 3 days ago

Fixes #1181:

The big example from #1181 now works correctly:

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
>
---
export function compile<T extends CompileOptions>(src: string, options?: T): Promise<
  (T extends { ast: true }?
    CivetAST
  :
    (T extends { sourceMap: true }? {
      code: string
      sourceMap: SourceMap
    }
    :
      string))
>