-
Notifications
You must be signed in to change notification settings - Fork 3
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
Generic variant usage with function as payload #13
Comments
Hey I haven't looked into this yet but it's more likely it's my fault than yours. Generic variants are... hard. I probably overlooked a case. I'll see what I can do. |
Hello @ohana54. I've finally found freedom from professional obligations (say that five times fast). I've been taking some creative license and rewriting most of the library for variant 3.0. As part of that, I tackled generics. There's a new interface I hope you'll find satisfactory. I've ported your example to use it. As a brief reminder, Variant 3.0 changes the purpose of the const Matcher = variant(onTerms(({T}) => ({
Specific: payload(T),
Custom: (payload: (v: typeof T) => boolean) => ({payload}),
})))
type Matcher<T, TType extends TypeNames<typeof Matcher> = undefined> = GVariantOf<typeof Matcher, TType, {T: T}>; Note you no longer need a With these changes (and executing on TS 4.2.4) I receive an error when using const matcher: Matcher<string> = Matcher.Custom((v: number) => v === 1); Full error:
I've added more details of the new generics implementation in this comment. |
Hi, sounds great!! I'll track the progress and wait for an alpha/beta version to try. |
Hi again :)
I'm trying to create a generic variant:
Specific
is pretty straight-forward, whereCustom
accepts a function that needs to use the generic type.When using
Specific
in a "wrong" way, I get an expected error:When using
Custom
in a "wrong" way, I don't get an error:I'm probably doing something wrong with the variant creation, how can I get the generic type of
Custom
to work?Thanks!
The text was updated successfully, but these errors were encountered: