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

Array.splice "deleteCount" argument description is somewhat insufficient #61081

Open
birgersp opened this issue Jan 30, 2025 · 1 comment · May be fixed by #61221
Open

Array.splice "deleteCount" argument description is somewhat insufficient #61081

birgersp opened this issue Jan 30, 2025 · 1 comment · May be fixed by #61221
Labels
Domain: Signature Help Information in editor tooltips when invoking a function call Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@birgersp
Copy link

birgersp commented Jan 30, 2025

⚙ Compilation target

ES2022

⚙ Library

lib.es5.d.ts (?)

Missing / Incorrect Definition

Array.splice

Sample Code

[1, 2, 3].splice(0, undefined) // what, exactly, should this return?

Documentation Link

I found myself using Array.splice but I wanted to erase from and index and the rest of the array.

Apparently, if I omit the "deleteCount" argument, the "rest of the array" is deleted.

(This is documented here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice#deletecount)

In my opinion, this should have been described in the library typings/JSDOC.

Image

This documentation should include a proper description of the "deleteCount" argument.

E.g. the docus should say something along the lines of:

@param - deleteCount The number of elements to remove. Omit this argument to remove all elements from index to the end.

@MartinJohns
Copy link
Contributor

TIL there are functions that behave different depending on omitting an argument, or passing an explicit undefined. Not very intuitive.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this Domain: Signature Help Information in editor tooltips when invoking a function call Experience Enhancement Noncontroversial enhancements labels Jan 30, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 30, 2025
@JulianTaub JulianTaub linked a pull request Feb 19, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Signature Help Information in editor tooltips when invoking a function call Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants