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

Float type support #329

Closed
fabiospampinato opened this issue Nov 30, 2021 · 1 comment · Fixed by #330
Closed

Float type support #329

fabiospampinato opened this issue Nov 30, 2021 · 1 comment · Fixed by #330

Comments

@fabiospampinato
Copy link
Contributor

The following seems to work for enforcing a float constrain on a number:

type Float<T extends number> =  `${T}` extends `${bigint}` ? never : T;

const onlyFloat = <T extends number> ( x: Float<T> ): void => {}

onlyFloat ( 123 ); // Error
onlyFloat ( 123.123 ); // OK

It's basically just Integer but with the results flipped.

@sindresorhus
Copy link
Owner

// @jonahsnider

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 a pull request may close this issue.

2 participants