Skip to content

throw a TypeError for non-Numbers and non-integral Numbers#30

Open
michaelficarra wants to merge 1 commit intomainfrom
typeerror
Open

throw a TypeError for non-Numbers and non-integral Numbers#30
michaelficarra wants to merge 1 commit intomainfrom
typeerror

Conversation

@michaelficarra
Copy link
Copy Markdown
Member

A TypeError is better than a RangeError for these values. Matches what we're doing for the second parameter of Iterator.prototype.includes: https://tc39.es/proposal-iterator-includes/.

@ljharb
Copy link
Copy Markdown
Member

ljharb commented Apr 1, 2026

Why is that better? It's the right type, it's just not in the right range.

@michaelficarra
Copy link
Copy Markdown
Member Author

@ljharb We still throw a RangeError for out-of-range values. The TypeError is if you pass Strings, Arrays, etc. or non-integral Numbers.

@ljharb
Copy link
Copy Markdown
Member

ljharb commented Apr 1, 2026

A non-integral number is an out of range value.

@michaelficarra
Copy link
Copy Markdown
Member Author

michaelficarra commented Apr 1, 2026

I guess this depends on what you think the expressive power of this non-existent type system is. I prefer to consider the domain of the function to be integral Numbers. Alternatives such as Numbers in the range [1, 2**32), integral Numbers in that range, all Numbers (which seems to be your preference), all primitives, or all JavaScript values are all equally as valid depending on what type system we're pretending is producing this TypeError.

@ljharb
Copy link
Copy Markdown
Member

ljharb commented Apr 1, 2026

To me, "type" is a superset of typeof - all Numbers are the same type, including NaN. I'd be surprised if most JS devs felt differently.

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