Skip to content

Codefix "Correct spelling" stops working when 3 spaces are missing, or suggests bad replacement #49557

Closed
@AlCalzone

Description

@AlCalzone

Bug Report

🔎 Search Terms

codefix spelling spaces

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground Link

💻 Code

enum NamesWithSpaces {
	"NoSpace",
	"One Space",
	"Has Two Spaces",
	"This Has Three Spaces",
	"And This Has Four Spaces",

	"Block One",
	"Block  Two",
	"Block   Three",
}

const test0 = NamesWithSpaces.NoSpace;
const test1 = NamesWithSpaces.OneSpace; // Codefix available
const test2 = NamesWithSpaces.HasTwoSpaces; // Codefix available
const test3 = NamesWithSpaces.ThisHasThreeSpaces; // NO codefix available
const test4 = NamesWithSpaces.AndThisHasFourSpaces; // NO codefix available

const block1 = NamesWithSpaces.BlockOne; // Codefix available
const block2 = NamesWithSpaces.BlockTwo; // Codefix available
const block3 = NamesWithSpaces.BlockThree; // NO codefix available

🙁 Actual behavior

Only the enum members with less than 3 spaces in the correct name have a suggestion to correct spelling (TS2551). The ones with 3 or more spaces don't (TS2339).

It seems to depend on the metric used to compare the strings. If we add a bunch of characters, the suggestions become even weirder:

enum NamesWithSpaces {
	"This Has Three Spaces_________________________________________________________",
	"And This Has Four Spaces_________________________________________________________",
}

const test3 = NamesWithSpaces.ThisHasThreeSpaces_________________________________________________________;
// ^ NO codefix available
const test4 = NamesWithSpaces.AndThisHasFourSpaces_________________________________________________________;
// Suggests "This Has Three Spaces_________________________________________________________"

The absolute (not normalized to string length) Damerau–Levenshtein distance (computed using https://github.com/el3um4s/Damerau-Levenshtein) between the correct replacements are 3 or 4 respectively (adding 3 or 4 spaces). The distance to the incorrect (but suggested) replacement is 10.

🙂 Expected behavior

Every one of those enum members should have a codefix available to correct spelling (by adding the spaces).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions