TypeError when spreadArray is used on a string containing an emoji/Unicode character
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, typescript
- Domain
- tooling
Research direction
Start with tslib.js around line 208 and the __spreadArray entry point, then reproduce the reported TypeError using the provided emoji snippet or CodeSandbox. Check the emitted helper under the relevant tsconfig options; done means spreading an emoji-containing string no longer throws and produces the expected length.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/tslib
-
question
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Difficulty 1/5 Under an hour Newbie friendliness 15/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
copse-dev/agent-pane#2953 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·