Microsoft/TypeScript

Annotated parameters are not used for inferring rest parameters

Open

#58,746 创建于 2024年6月3日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
Domain: check: Type InferenceHelp WantedPossible Improvement

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

annotated, "rest parameter"

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAWwNYEFrzAHgJJgAOIUiApgB5RlgAmAzogIZgCeA2gLoB8AFE1gQAuRAG8AUIimJgARiG8AdMor0hBYlACUiALzdEANzgxaAGknTgAJgXLFq9URI79Rk+fEBfHaK-jxNExYBF4JaRlZXgoheigAJxgwAHMzRFYhMBBkACMyeN8vC0spG2i01kKLCIB6GsQKZjp05niyRCTgfLbaZkYAIhZWfurpOvJDGkQoAAs4EGSZmWsOxk7usl6mAeiROMSUipEs3PzXA2NTfu8tAG5xIA

💻 Code


function mkAction<Input extends any[]>(action: {
    f1:(...xs:Input) => void,
    f2:(...xs:Input) => void,
}) {}

mkAction({
    f1(x:string, y:number) {},

    f2(x, y) {},
    // x and y are inferred as "any",
    // even though f2 is inferred as "(x: string, y: number) => void"
});

🙁 Actual behavior

Arguments "x" and "y" are inferred as "any", even though "f2" has the correct type (x: string, y: number) => void

🙂 Expected behavior

I would expect inference of x: string and y: number for the arguments of "f2".

Additional information about the issue

No response

贡献者指南