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

Methods that return a specific range of numbers should have more accurate return types #2512

Closed
ahkhanjani opened this issue Nov 22, 2023 · 1 comment

Comments

@ahkhanjani
Copy link

ahkhanjani commented Nov 22, 2023

E.g. .day() returns a number ranged from 0 to 6, yet the return type is number. It should instead be 0 | 1 | 2 | 3 | 4 | 5 | 6. If this doesn't cause any real issues that I'm unaware of, it can be beneficial in some situations. For example:

const WEEKDAYS = ['Sunday', 'Monday', ..., 'Friday'] as const;

WEEKDAYS[dayjs().day()]; // Currently can be undefined.

With the more accurate return type there will be no need for a runtime check or an exclamation mark.

@ahkhanjani
Copy link
Author

Closing since #2630

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

1 participant