Skip to content

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

RyanCavanaugh
RyanCavanaugh previously approved these changes Nov 27, 2024
@Pascal-So
Copy link
Author

note that i didn't get the tests to pass. i experimented a bit locally and to me it seemed like the process is to copy over the generated files as the new baseline references, but even after doing that the tests still didn't pass.

does anyone know how i get the test runner to print the actual diffs rather than just fail the test?

@jakebailey
Copy link
Member

See https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md#managing-the-baselines

You'd just need to run the tests and then run the "baseline-accept" task.

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 28, 2024
@Pascal-So
Copy link
Author

@jakebailey ah, thanks for the hint! turns out my problem was that my editor changed some crlf's to lf when I tried to manually copy over the updated files before :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog 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

4 participants