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

custom regex as type that accepts only matching strings #60292

Closed
6 tasks done
antonioconselheiro opened this issue Oct 20, 2024 · 4 comments
Closed
6 tasks done

custom regex as type that accepts only matching strings #60292

antonioconselheiro opened this issue Oct 20, 2024 · 4 comments

Comments

@antonioconselheiro
Copy link

antonioconselheiro commented Oct 20, 2024

πŸ” Search Terms

"regex type", "regular expression type"

βœ… Viability Checklist

⭐ Suggestion

Hey people, how are you doing?
I would like to suggest use regex as a custom type:

const hexId: /[a-z\d]+/ = 'b9283d50ff2db1d95c08395e73556bc5c147e22125280e78c569603ac6854fe6';

also

type HexString = /[a-z\d]+/;
const hexId: HexString = 'b9283d50ff2db1d95c08395e73556bc5c147e22125280e78c569603ac6854fe6';

I searched through the closed and open issues and didn't find any suggestions exactly like this, but maybe I didn't look hard enough, because it seems like a very obvious suggestion to me.

πŸ“ƒ Motivating Example

This will help me create any custom string type.

πŸ’» Use Cases

  1. What do you want to use this for?
    After validate a string with a regex, by using the regex as type I will be suure that I no need validate that data again.

  2. What shortcomings exist with current approaches?
    I found nothing functional that can bring me something like this.

  3. What workarounds are you using in the meantime?
    I'm using string type and crying.

@Josh-Cena
Copy link
Contributor

#41160

@antonioconselheiro
Copy link
Author

I found this issue, but I was not sure if was exactly that

@MartinJohns
Copy link
Contributor

It is exactly that.

@antonioconselheiro
Copy link
Author

closed as duplicated

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

No branches or pull requests

3 participants