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

TypeError when spreadArray is used on a string containing an emoji/Unicode character #175

Open
marcandrews opened this issue Mar 21, 2022 · 1 comment · May be fixed by #177
Open

TypeError when spreadArray is used on a string containing an emoji/Unicode character #175

marcandrews opened this issue Mar 21, 2022 · 1 comment · May be fixed by #177

Comments

@marcandrews
Copy link

Expected behavior

No error occurs when spreadArray is used on a string containing an emoji/Unicode character.

Current behavior

When spreadArray is used on a string containing an emoji/Unicode character, the following error occurs:

TypeError: Cannot use 'in' operator to search for '0' in ❤️ at __spreadArray

I believe the problem is related to https://github.com/microsoft/tslib/blob/2.3.1/tslib.js#L208 because if you run ...

'0' in '❤️';

// ... or ...

__spreadArray([], "❤️", true);

... the same error occurs.

Steps to reproduce

https://codesandbox.io/s/beautiful-cohen-86fygb?file=/src/index.js:220-251

Context

I need to replace some emojis with images so I am using emoji-regex to find them and get the true length of the emoji so that it can be substituted, they recommend using ...

[...emoji].length

... that under certain tsconfig.json options, will be transpiled to ...

__spreadArray([], emoji, true).length

I have tried other variations, including Array.from() and emoji.length, and only the variation above yields accurate lengths. Fortunately, swallowing the error in a try-catch seems to work so it seems the error is not critical for spreadArray to function for some reason and I do not know why.

jcfranco added a commit to jcfranco/tslib that referenced this issue May 17, 2022
@jcfranco jcfranco linked a pull request May 17, 2022 that will close this issue
@jcfranco
Copy link

We ran into this recently in a project that uses color where an innocent linting fix exposed this bug.

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 a pull request may close this issue.

2 participants