Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug: [no-misused-spread] report for string spread harmfully conflates Unicode code points with UTF-16 code units #10745

Closed
Labels
awaiting responseIssues waiting for a reply from the OP or another partybugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@andersk

Description

@andersk

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.6.3&fileType=.tsx&code=MYewdgzgLgBBMF4YCJBd4Ycw3Bvu4Gx1kG4AoA0SEAGwFMA6MkAcwAoApAZQHkA5K6AJwEswdPgDMAngwDaVaRAC6ASnmEA9MpgBhEDx4VgUAFwwJaZABpkWM8lyyCqmACEArrDAgAtAFs%2BEJxAoAJu4QAA46AIYBMKCeIWThAvBQABYUOqYw4WBRvnR0FNAQ%2BkQkEOTUtIysnNxQ-IIi4hDccXxQDMjIikp2agCSYKDaugZGJuYAOk4BABwAbADsVlMBAcJzVjYEQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oFtLlZkiACa1kxaIgCGQ9FETRoHaJHBgAviDVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

consts="螺𩷶屬";console.log(JSON.stringify([...s]));// Correct: ["螺","𩷶","屬"]// But no-misused-spread complains there, and suggests:console.log(JSON.stringify(s.split("")));// Incorrect: ["螺","\ud867","\uddf6","屬"]

ESLint Config

module.exports={"rules":{"@typescript-eslint/no-misused-spread":"error"}}

tsconfig

{"compilerOptions": {"strictNullChecks":true  }}

Expected Result

In JavaScript, string spreading is the correct way to split a string into Unicode code points. It should not be an error.

Actual Result

error Using the spread operator on a string can cause unexpected behavior. Prefer `.split('')` instead. @typescript-eslint-no-misused-spread

But.split('') splits a string into UTF-16 code units, not Unicode code points. For characters outside the basic multilingual plane, this produces invalid unpaired surrogates.

Additional Info

This rule was introduced with a justification linking to the blog post “Strings Shouldn’t Be Iterable By Default”. But this post is about how to design better languages in the future, not how to use the languages we already have.

In the JavaScript language we have,[...s]is the correct way to split a string into Unicode code points, and.split('') does not do that correctly. The suggestion is harmful and will result in the introduction of subtle internationalization bugs triggered with less common languages (and emoji).

There isn’t another good way to correctly split a string into Unicode code points, so this rule should just be disabled for strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting responseIssues waiting for a reply from the OP or another partybugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp