-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature request / idea: simplify types for fc.record
#5434
Comments
fc.record
Also I'm not sure which versions of TypeScript you've committed to supporting, so I created the playground in the oldest version that shipped TwoSlash annotations. That was so you could more easily "see" the types, but I think this approach could work with older versions than 4.7. One more thing, I'm realizing now that if a user constraints a record with |
Hey man, looks cool 🙂 I have to admit, both these and the original types take me a bit to digest. Why are all these utility types union-ed with type Keep<T, K extends keyof T> = never | { [P in K]: T[P] }
// ^^^^^^^ |
Thanks a lot for the suggestion. It could maybe be useful to rework the typings for I have two objectives in mind for record:
|
Said differently why not if it proves easier (I have not taken time to compare the current approach with your, I'll check later), but let's target the next major (don't want to break typings of existing users). regarding my two points above I think they are probably the target we should aim if we want to rewrite the type definition of record (2nd being more important than the overload given the value it would add). |
Hey @gruhn , I've been heads down on a project and didn't see your comment. The union with never is an identity operation:
The dual operation is
Seems kinda useless, but the reason is due to an implementation detail of the typechecker -- unifying or intersecting 2 types forces the typechecker to evaluate the pair, which forces evaluation. If you've ever wished you could "see" the type that |
@dubzzz can you tell me more about what you mean here? Looking at the JSDocs for I added that to the playground so you can see what I mean. Also if you're pressed for time, I suggest skipping past the types and going straight to the usage at the bottom. Edit: fixed a bug in the types. |
💡 Idea
Hi Nicolas -- first of all, thank you for your work on
fast-check
. It might be the only TS library I recommend to other devs without qualification :)Anyway, in my own projects and at work, I usually add a package that re-exports
fast-check
, and includes various extensions that my team wants to use in more than one place.One pattern I've found that helps seem to make the library "stick" a little better is to export a version of
fc.record
that ships a different set of types. I've included a version of it in the playground at the bottom of this issue if you'd like to play with it.I wonder, would you accept a pull request that simplified the types for
fc.record
? I can submit that this weekend, if so, and would be happy to make any requested changes and help maintain them.Motivation
The motivation is to make adoption of
fast-check
easier. One thing I've been experimenting with recently is usingfast-check
the way some devs usezod
-- as the source of truth for my types.For that to work, I think something like the change I'm proposing below is necessary, since otherwise the inferred types become quite difficult to read, especially when nested.
Example
Playground
The text was updated successfully, but these errors were encountered: