[PR] Return union void for some string functions
Closes #8284
codePointAt and ''[123] has the potential to return undefined. This change will enforce users to put guards around these use cases to provide safer string manipulation.
For my index test I had to write it as (new String()[123]: string); because (''[123]: string) wasn't throwing an error. Not sure if I'm missing something here because the previous test that uses string literal works fine.
@Brianzchen Looks good, also thanks for the parameter name changes.
I don't really care about flow anymore these days though, sorry.
I've removed the index of check to make this PR a bit easier to get in. Flow team has already expressed that is an area of unsoundness that they are prepared to allow for an easier dev experience.
@nnmrts I understand, hope things get better and you feel interested again soon 😄
I think so, the definition if it hasn't been corrected is in fact wrong.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt#return_value
It's documented as
If index is out of the range of 0 – str.length - 1, codePointAt() returns undefined.
https://github.com/facebook/flow/commit/ec8a209b46a4635b6a51bdf148a341980fdf3900 would resolve one of the issue. We don't plan to touch the other one, because TS is also being unsound there, and it would be too disruptive.