-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve inference of return types
- Loading branch information
1 parent
8d59668
commit aec6f75
Showing
3 changed files
with
502 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
}); | ||
} | ||
``` |
Oops, something went wrong.