Skip to content

fix: update interface Input type parameter to contravariant type #79

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

Merged
merged 1 commit into from
Oct 27, 2022

Conversation

didavid61202
Copy link
Collaborator

@didavid61202 didavid61202 commented Oct 27, 2022

Updates

  1. Add in contravariant annotation to type parameter V of Input type:
interface Input<
-  V extends string,
+  in V extends string,
  G extends string = never,
  C extends (string | undefined)[] = [] > { ... }
  1. Refactor InputSource to make Input accept any V type as it is set as contravariant type:
- export type InputSource<S extends string = never, T extends string = never> = S | Input<S, T>
+ export type InputSource<S extends string = string, T extends string = never> = S | Input<any, T>
  1. Update/refactor IfUnwrapped type's all parameters to extends string instead of Input (makes usage more concise)
- any: () => IfUnwrapped<V, Input<`(?:${V})*`, G>, Input<`${V}*`, G, C>>
+ any: () => Input<IfUnwrapped<V, `(?:${V})*`, `${V}*`>, G, C>
  1. fix ts comments for and and times chaining Input helpers

Note

This PR should resolve the type inferencing issue (using extractRegExp helper or directly using createRegExp) when implementing new letter.lowercase and letter.uppercase helper inputs in PR #77 and any future implementations of similar input helpers design to be accessed by `dot notation.

@vercel
Copy link

vercel bot commented Oct 27, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
magic-regexp ✅ Ready (Inspect) Visit Preview Oct 27, 2022 at 2:20PM (UTC)

@what-the-diff
Copy link

what-the-diff bot commented Oct 27, 2022

  • Changed the type of anyOf to accept any input source
  • Added a comment for and operator
  • Fixed some types in escape, sources and wrap files

@ccjmne
Copy link
Contributor

ccjmne commented Oct 27, 2022

Woah, great stuff!
I have never heard of the "in contravariant annotation"... I'll read about it tonight and try to learn from your implementation.
Thank you! 🙇‍♀️

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! ❤️

@danielroe danielroe merged commit c9707a2 into main Oct 27, 2022
@danielroe danielroe deleted the fix/input-type-variance branch October 27, 2022 14:59
@didavid61202
Copy link
Collaborator Author

didavid61202 commented Oct 27, 2022

note: this change (using Variance Annotations for Type Parameters ) will also limit the typescript version to be >4.7, and similar ts version limitation also get mentioned in #62.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants