Skip to content

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

Open
@marcandrews

Description

@marcandrews

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions