← Back to context

Comment by wk_end

10 hours ago

I mean, you can trivially do it with a (non-G) ADT, if you're content with wrapping the return value.

OTOH you can do this in TypeScript easily without wrapping; it could return a union type `number | string`.

Isn't that just saying you can do dependent types in TypeScript easily so long as you're willing to give up type checking?

  • Actually, it's even simpler: you should just be able to use signature overloading:

      myFunc(x: true): number
      myFunc(x: false): string
    

    The article's assertion that TypeScript can't represent this is quite false.