Skip to content
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

feat(match): allow to match strictly and customize predicate #106

Closed
wants to merge 0 commits into from

Conversation

ecyrbe
Copy link
Collaborator

@ecyrbe ecyrbe commented Aug 1, 2023

This allows to match exactly and also customize the predicate to match or pass a checker.
So with this, you can match types only. So not just check if something extends a string, but check that something is actually a type string:

interface ExtendsTypeOf extends Fn {
  return: this["arg0"] extends this["arg1"] ? true: false;
}

interface IsArray extends Fn {
  return: this["arg0"] extends unknown[] ? true: false;
}


type TestTypes<T> = Match<T,[
   Match.WithEqual<string, "string">,
   Match.WithEqual<number, "number">,
   Match.WithEqual<boolean, "boolean">,
   Match.WithEqual<null, "null">,
   Match.WithPredicate<ExtendsTypeOf, Record<string,unknown> , "object">, // same as `Match.With<Record<string, unknown>, "object">`
   Match.With<IsArray , "array">, // same as `Match.With<unknown[], "array">`
   Match.With<any, "not a json type">
  ]>;

@ecyrbe ecyrbe changed the title feat(match): allow to match strictly feat(match): allow to match strictly and with predicate Aug 1, 2023
@ecyrbe

This comment was marked as resolved.

@ecyrbe ecyrbe changed the title feat(match): allow to match strictly and with predicate feat(match): allow to match strictly and customize predicate Aug 1, 2023
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.

None yet

2 participants