microsoft / microsoft/TypeScript
Broken property suggestions due to a successfully contextually typed function
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
```ts
declare function makeRequest<
QueryParam
>(
getFn: (client: { prop: number }) => QueryParam,
params: NoInfer,
): 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 here suggests globals, not `prop` like it should.
{},
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);
makeRequest(
(client: { prop: number }) => client,
// Using autocomplete here now suggests keys.
{},
);
```
Sub-part of https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2759515773 with parts pointed out with https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648
See @Andarist's analysis at https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的最小 TypeScript 复现开始,并阅读 issue #46916 及其评论中链接的分析。跟踪泛型函数的上下文类型推断和类型推断过程,然后验证 QueryParam 是从 callback 推断出来的,并确认 params 的自动补全会在没有显式 callback 注解的情况下提供 prop。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100