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

Fix return type annotations for the random() method #492

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

DavidTimms
Copy link
Contributor

The random() method on a type generates a random value conforming to the type of the schema. The TypeScript type definitions for this method were incorrect - they claimed that this method returned the type object itself. For instance, calling random on a BooleanType returns a boolean, not a BooleanType. I assume this has gone undetected for years, because this method is rarely used.

Because the types for schemas do not carry complex type information in generics, many of these return types are rather imprecise. I have had to resort to unknown quite often, because more exact types are not available. I have chose unknown over any, to maintain type safety.

Copy link
Owner

@mtth mtth 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 for the fix. Just a quick comment.

types/index.d.ts Outdated Show resolved Hide resolved
@mtth mtth merged commit f4c6168 into mtth:master Jan 9, 2025
3 checks passed
@DavidTimms
Copy link
Contributor Author

@mtth Thanks for merging this.

Do you have any plans for a release in the near future? I noticed there hasn't been a release in the a couple of years, so there are a few unreleased fixes built up now.

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.

2 participants