microsoft / microsoft/TypeScript

Issue: TypeScript autocomplete for template literal types ignores user's Quote Style preference

未关闭
#63,603 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Domain: LS: Completion Lists
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

🔎 Search Terms

List of keywords : "double", "quote", "preference", "style", "autcomplete", "template", "literral"

🕗 Version & Regression Information

TS Version : 6.0.3 or 7.0-rc

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAKghgIwDYQHJwLbQLxQOTACMeUAPvsAEx4DcAUKJFAMID2SArhgHbpZS48ASwAmJcngBucThFoNw0eMghtOPAVAAGAEgDeylHwgBfAHT61XXplNb6jaAClWQ7pr10oUVtwBcUAAKcABOwEIyADwAShAAxqwhIpGGquzWADSwiChWPAB8+fQm9AncAM7AUMAQlQEubh5ePv5Qnt5QzSZ0JUA

💻 Code
type TableName = 't1' | 't2';
type ColumnName = 'id' | 'value';
type TableColumn = `${TableName}.${ColumnName}`;

type Join = {
  on: Partial<Record<TableColumn, TableColumn>>;
};

const test: Join = {
  on: {
    // Trigger autocomplete inside the object
  }
};
🙁 Actual behavior

The key is inserted using double quotes (e.g., "t1.id": ...), overriding the user's preference for single quotes.

🙂 Expected behavior

The key should be inserted using the quote style defined in the editor's preferences (e.g., single quotes if 'single' is selected).

Additional information about the issue

When using template literal types as keys in a Record or object mapping, the TypeScript language service's autocomplete functionality consistently forces double quotes (") when inserting the suggested keys, regardless of the user's configured javascript.preferences.quoteStyle or typescript.preferences.quoteStyle settings.

https://github.com/user-attachments/assets/e562b5ab-bbd7-48bd-96f8-a9181f03ba2e

This behavior is inconsistent with how standard string keys or property names are handled and complicates code consistency when working with complex template literal types in type-safe mappings.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在编辑器引号偏好设置为单引号的情况下,复现链接的 TypeScript Playground 中的 template-literal Record 示例。首先跟踪 TypeScript language service 针对对象键的自动补全路径,然后验证接受建议的键后,对于 JavaScript 和 TypeScript 偏好设置,配置的引号样式都能得到保留。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
developer-experience
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。