grafana / cuetsy

Experimental CUE->TypeScript exporter
Apache License 2.0
106 stars 8 forks source link

Support for generating generic types? #62

Closed sdboyer closed 2 years ago

sdboyer commented 2 years ago

Currently, cuetsy can't generate generic Typescript types.

I'm pretty uncomfortable with the idea of generating generic types in cuetsy, as it's hard to see how we could do so in a way that maintains at least rough type equivalence. It's especially unclear how how generated default* would be reconciled with generics in the raw generated types.

In general, i prefer a "veneering" strategy, where it's expected that hand-written code is layered on top of the generic code that can add generic types. That way, the typescript type checker can enforce that whatever generics are layered on type, they're type constraints/refinements on the generated raw types.

But, i'm open to counterarguments, which folks are welcome to make in this issue, if they want :)

sdboyer commented 2 years ago

We're now settled against this, primarily because of the default* issue. Veneering is the preferred strategy (see grafana/grafana#54816 for where we introduced it).

Could reopen if someone has something nifty for how we handle defaults, coupled with a strong use case to justify.