Skip to content

Ensure method calls on unions get accurate types#4309

Open
KimlikDAO-bot wants to merge 1 commit intogoogle:masterfrom
KimlikDAO-bot:method_on_union
Open

Ensure method calls on unions get accurate types#4309
KimlikDAO-bot wants to merge 1 commit intogoogle:masterfrom
KimlikDAO-bot:method_on_union

Conversation

@KimlikDAO-bot
Copy link
Copy Markdown
Contributor

@KimlikDAO-bot KimlikDAO-bot commented Apr 11, 2026

  • Ensure that Array, ArrayBuffer, ReadonlyArray, String, TypedArray have consistent slice() signatures so method calls over the union gets typed correctly.

  • Ensure that BigInt.prototype.toString and Number.prototype.toString are typed consistently so (bigint|number).toString() gets inferred correctly.

  • Add tests for indexOf, includes, slice, toString so that the signatures of these cognate methods do not drift by accident.

Note: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice claims that String.prototype.slice() first argument is required at the beginning of the doc, but later admits "If indexStart is omitted, undefined, or cannot be converted to a number, it's treated as 0."

Making both params of String.prototype.slice optional is consistent with the runtime and common TypeScript typings.

- Ensure that Array, ArrayBuffer, ReadonlyArray, String, TypedArray
  have consistent slice() signatures so method calls over the union
  gets typed correctly.

- Ensure that BigInt.prototype.toString and Number.prototype.toString
  are typed consistently so (bigint|number).toString() gets inferred
  correctly.

- Add tests for indexOf, includes, slice, toString so that the
  signatures of these cognate methods do not drift by accident.

Note: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
claims that String.prototype.slice() first argument is required at the
beginning of the doc, but later admits "If indexStart is omitted,
undefined, or cannot be converted to a number, it's treated as 0."

Making both params of String.prototype.slice is consistent with the
runtime and common TypeScript typings.
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.

1 participant