microsoft / microsoft/TypeScript
Broken Autocomplete and Type Display For Parameters Dependent on Transitively Contextually Typed Return Type
还没有人认领这个 Issue。
- 主要语言
- 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
💻 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 开始,比较 issue 的 Code 部分中的两个 makeRequest 调用。调查上下文类型、传递推断的返回类型以及 NoInfer 行为;完成的标准是自动补全会建议相关属性,并且显示的参数类型与用于验证的类型一致。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100