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: add intRange type #707

Merged
merged 6 commits into from Oct 17, 2023
Merged

Conversation

Emiyaaaaa
Copy link
Collaborator

@Emiyaaaaa Emiyaaaaa commented Oct 14, 2023

Fixes #669

@sindresorhus
Copy link
Owner

Thanks for contributing :)

@sindresorhus
Copy link
Owner

How does this compare to https://twitter.com/anuraghazru/status/1573328100246822917 and #669 (comment) ?

@sindresorhus
Copy link
Owner

I'm a little bit concerned about possible type complexity explosion here. Have you tested it with larger ranges?

Maybe it would make sense to add an overload to use the simpler way when "step" is not specified?

@sindresorhus
Copy link
Owner

// @lucasteles @tommy-mitchell

@Emiyaaaaa
Copy link
Collaborator Author

Emiyaaaaa commented Oct 15, 2023

I'm a little bit concerned about possible type complexity explosion here. Have you tested it with larger ranges?

Maybe it would make sense to add an overload to use the simpler way when "step" is not specified?

You are right, with "step" is significantly slower than without "step". I found EqualOrMoreThan is very performance-impairing, but it is necessary for "step"

I should use overload and try to resolve performance question with Step.

ps: range limit is 0-999 in any implementation

@Emiyaaaaa
Copy link
Collaborator Author

Emiyaaaaa commented Oct 15, 2023

How does this compare to https://twitter.com/anuraghazru/status/1573328100246822917 and #669 (comment) ?

these are the same principle: generate a Start to End tuple like type RangeArray<5, 10> = [5,6,7,8,9], and transform it to union.

anuraghazru and #669 way is generate a number tuple A of "0 - Start" and anonter number tuple B of "0 - End". then Exclude<B, A>

My why is generate a tuple of "0 - End", and use any other type when tuple index is small than Start, (e.x. type IntRangeArray<3, 5> = [never, never, never, 3, 4]), than transform tuple to union and exclude never, so ohter way created two tuple but my way just create one tuple and just need one loop.

anuraghazru's "float range" implementation way is transform IntRange result to string union, then add the decimals, finally transform it to number union

@Emiyaaaaa
Copy link
Collaborator Author

Emiyaaaaa commented Oct 15, 2023

I'm a little bit concerned about possible type complexity explosion here. Have you tested it with larger ranges?
Maybe it would make sense to add an overload to use the simpler way when "step" is not specified?

You are right, with "step" is significantly slower than without "step". I found EqualOrMoreThan is very performance-impairing, but it is necessary for "step"

I should use overload and try to resolve performance question with Step.

ps: range limit is 0-999 in any implementation

@sindresorhus The latest commit used overload and improved performance when use Step, now can fast load IntRange<0, 999, 2> without loading in vscode

readme.md Outdated Show resolved Hide resolved
source/int-range.d.ts Outdated Show resolved Hide resolved
source/int-range.d.ts Outdated Show resolved Hide resolved
source/int-range.d.ts Outdated Show resolved Hide resolved
source/int-range.d.ts Outdated Show resolved Hide resolved
@sindresorhus sindresorhus merged commit e5d145d into sindresorhus:main Oct 17, 2023
6 checks passed
@sindresorhus
Copy link
Owner

Thanks :)

@BrendanC23 BrendanC23 mentioned this pull request Jan 23, 2024
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.

Proposal: Enumerate and IntRange
2 participants