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

Document indexOf return value when not found #60569

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Pascal-So
Copy link

@Pascal-So Pascal-So commented Nov 23, 2024

fixes #60570

The documentation for indexOf on arrays already mentioned that the method returns -1 when the value is not found:

Screenshot_20241123_133946

But for strings, this information was missing thus far:

Screenshot_20241123_134018

Of course the user would have been able to puzzle this together by seeing that the return type is just number, not something like number | undefined, thus allowing them to figure out that the sentinel value probably must be -1. Nevertheless, having to stop and think about this is unnecessary friction for people who don't remember this fact by heart, for example people who jump between programming languages a lot.

I also noticed that the same information was missing for all the TypedArrays, so I went ahead and extended the docs there as well.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 23, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@Pascal-So
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Needs merge
Development

Successfully merging this pull request may close these issues.

Extend documentation of String.indexOf to mention what happens when substring is not found
3 participants