Re: [heycam/webidl] Add bigint type (#525)

> Oh, and unlike a lot of overload scenarios, the "overload numeric and bigint" is not completely insane, because if you want to have an API that takes "numbers of arbitrary size" 

I'm not sure if that's in line with the goals of the BigInt proposal, to have new APIs which take both out of the box by design. I think most APIs fall into the category of "logically making sense for arbitrary-size integers" or "logically making sense for floating point values"; there's definitely stuff in the intersection ("logically making sense for only small integers"), and for that, Number works well. I was imagining overloading would mostly make sense when trying to upgrade an API from a Number version to a BigInt version, when we initially thought that it made sense only on small integers, but it turned out it was also important on large integers.

> Option 1 is slightly harder to use as an API, and the reasoning behind "0" being OK but 0 not being OK is subtle and likely to make anyone trying to just pass a small numeric constant be annoyed.

The hypothesis of the BigInt proposal design is that programmers will keep track of whether something is a BigInt operation or a Number operation, and the types of scalar values, and not do things generically. All the JS programmers I've heard from seem basically on board with this design. Part of this here is, even for small numeric constants, you put an `n` at the end of the literal. I don't want to encourage a proliferation of Web APIs which 

> Or we could make es-to-idl conversion for bigint more like https://tc39.github.io/proposal-bigint/#sec-bigint-constructor-number-value than like https://tc39.github.io/proposal-bigint/#sec-to-bigint I suppose....

If we did that, and privileged the bigint path, we'd get surprising exceptions for things like `f("3.2")`, wouldn't we?

I don't see a great answer here which makes everything beautiful, intuitive and not throw errors. Maybe we should start by making `bigint` and `number` indistinguishable, and make sure that unions throw in the ambiguous case. I uploaded a patch which does that.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/pull/525#issuecomment-369977523

Received on Friday, 2 March 2018 16:42:59 UTC