Skip to content

Commit

Permalink
feat: improve inference of return types
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorales committed Jul 21, 2024
1 parent 8d59668 commit aec6f75
Show file tree
Hide file tree
Showing 3 changed files with 502 additions and 88 deletions.
22 changes: 22 additions & 0 deletions .changeset/thin-dancers-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'exhaustive': patch
---

Improve inference of return types with new generic value

The return type of `exhaustive` and `exhaustive.tag` will now be inferred based on the return type of the callback function.

```ts
type Union = 'IDLE' | 'LOADING' | 'SUCCESS' | 'ERROR';

type HumanReadableUnion = 'idle' | 'loading' | 'success' | 'error';

function unionToHumanReadableString(union: Union): HumanReadableUnion {
return exhaustive(union, {
IDLE: () => 'idle',
LOADING: () => 'loading',
SUCCESS: () => 'success',
ERROR: (value) => value.toLowerCase(), // type `string` is not assignable to type `HumanReadableUnion`
});
}
```
Loading

0 comments on commit aec6f75

Please sign in to comment.