4
lorentz
3y

It's probably no news that I love Typescript's versatile and powerful generics. Today I found what is probably the most brilliant use of these tools to solve a real problem. This package exports one generic type which takes one generic argument, reads it like a JSON schema and returns the Typescript type for it:

https://github.com/YuJianrong/...

Comments
  • 2
    There's a typo on your website.

    >I love open source snd mathematics.

    Should be 'and'
  • 0
    Neat
  • 0
    I love c++ templates more.
  • 0
    Sounds like it's basically F# type providers, but more hacked together? Would definitely recommend looking at that.
  • 0
    @RememberMe Typescript's compile time types bear no relation to any actual input, and ensuring that input matches your types is tedious. This allows me to define exported interfaces as JSON schemas and then pass those to a runtime validator, while simultaneously passing them into Typescript. While this still forces me to maintain two separate definitions of some types (because I ultimately want to use Typescript and not JSONSchema to define my internal types) I am forced to keep the definitions assignable to each other by a compile-time check.
    So a bit similar but solving a dumber problem.
  • 0
    @homo-lorens that sounds like a thing I hate: overcomplicating
  • 1
    @mundo03 Overcomplicating to be able to reason about types is the second best thing after having the language and IO channels designed around that ability.
Add Comment