unsplash / sum-types

Safe, ergonomic, non-generic sum types in TypeScript.
https://unsplash.github.io/sum-types/
MIT License
42 stars 2 forks source link

Improved missing property error reporting #7

Closed samhh closed 2 years ago

samhh commented 3 years ago

Because our match function(s) can either be exhaustive or wildcard, the error message in case of missing properties pushes you towards adding the wildcard case. It'd be a lot more helpful if we could instead get help about which exhaustive properties are missing.

samhh commented 2 years ago

A minimal repro:

// The compiler highlights that `bad` is missing, but we'd instead like to
// prioritise reporting the absence of `good`.
// You can flip the union in `F` and drop the `Partial` in `H` to accomplish
// this, but we need to keep the `Partial` (functionally at least).
type F<A extends string> = G<A> | H<A>
type G<A extends string> = { [K in A]: any }
type H<A extends string> = Partial<G<A>> & { bad: any }
const x: F<'good'> = {}