Microsoft/TypeScript

Rename doesn't work on declaration whose name is a string literal

Open

#57.026 aberto em 11 de jan. de 2024

Ver no GitHub
 (0 comments) (5 reactions) (0 assignees)TypeScript (6.726 forks)batch import
Domain: LS: RefactoringsExperience EnhancementHelp WantedSuggestion

Métricas do repositório

Stars
 (48.455 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)

Description

Follow up to https://github.com/microsoft/TypeScript/issues/56052, which was fixed by https://github.com/microsoft/TypeScript/pull/56061. That fix means that rename from string literal values that are contextually typed by the type of the string-literal-named property do work. But renames on the actual property declaration still don't.

interface I {
    "Prop 1 Foo": string
    // ^-- rename here doesn't work
}
declare const fn: <K extends keyof I>(p: K) => void
fn("Prop 1 Foo")

Playground link

As before, if you use constant with a literal type, renaming the literal type does work:

declare const indirect: "Prop 1 Foo"
interface I {
  [indirect]: string
}
// ... same as before ...

Guia do colaborador