microsoft / microsoft/TypeScript

Broken Autocomplete and Type Display For Parameters Dependent on Transitively Contextually Typed Return Type

未关闭
#61,500 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Domain: check: Contextual Types Help Wanted
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

🔎 Search Terms

contextually typed autocomplete, contextually typed type display, contextual return type

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ
⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=2&ssc=13&pln=3&pc=3#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwFsoBrEAJRAEdkQBnDAHgCh54BFGmATwAVYoCTAHwAKFvADmIDADFUALngjIWEKgyKA3vAAOMHDsWpkBAEYgY8AL4BKeAF4h7Tr34EANOJ1vaigHI4AJKoiBYMHBauMAJCnjaKAG44WMAA3ExMAPSZ8AASOAkWWKgS8AUW8AAGRKQU1HQYlfC0ABY4AO608BgtUBhVEdx80QRNWF3FoTBwwPBQXZVoxKgdqE1QqLOV3iO0Y104pvRqtFimEFzdXDogs-NVSyvta-DtLVhgLfDj3+h4EjBkDhkF12lget13l0wFAIBBvl0NvALPoYAA6Jg1chUGj0MSsVjKCCqdR2RzwFRqDCeAnwbLwACqpxKc2QGBwYBwBB0EGkCBaFgQtGQEik9C6K10+huMAwl1IXFoGNpmisnnpAD14ABBGASExUsqIK43eAAclVZoR8BW-XmpwkqCg5wQ7N0bj5lhwxrlpotUoMRhM5hgqWsZoxNnSmJI2PqePEhMp6i0AcMNuDFVsDicyepibpOSZxVKUDZHK5PL58AFcBtHWaIrFGC6CqVBdVcVSQA

💻 Code
declare function makeRequest<
  QueryParam
>(
  getFn: (client: { prop: number }) => QueryParam,
  params: NoInfer<QueryParam>,
): void;

// Hovering over `makeRequest` shows that `QueryParam` is inferred as `unknown` and `params` is obstensibly typed as `unknown` which is incongruous with this call is an error.
makeRequest(
    (client) => client,
    {},  // Using autocomplete in the object suggests no property keys.
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);

makeRequest(
    (client: { prop: number }) => client,
    {}, // Using autocomplete here now suggests keys.
);
🙁 Actual behavior

The first call to makeRequest where client is contextually typed has broken autocomplete. No relevant properties are suggested. Furthermore hovering over makeRequest shows, incongruously, that params: unknown and yet the call {} causes an error expecting it to be of type { prop: number; }

🙂 Expected behavior

I expected auto-complete to work in all cases and the type display to be consistent.

Additional information about the issue

Related to #46916 but @Andarist hypothesized that the underlying root cause is different in this case so I decided to open it as its own issue for tracking purposes.

贡献指南

打开贡献指南

从这里开始

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

调研方向

从链接的 TypeScript Playground 开始,比较 issue 的 Code 部分中的两个 makeRequest 调用。调查上下文类型、传递推断的返回类型以及 NoInfer 行为;完成的标准是自动补全会建议相关属性,并且显示的参数类型与用于验证的类型一致。

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

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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