Microsoft/TypeScript

Reverse mapped type inference fails to infer from annotated parameters in partially-inferrable object types

Open

#57,788 opened on 2024幎3月15日

GitHub で芋る
 (1 comment) (0 reactions) (0 assignees)TypeScript (6,726 forks)batch import
Domain: Mapped TypesHelp WantedPossible Improvement

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (平均マヌゞ 6d 17h) (30d で 9 merged PRs)

説明

🔎 Search Terms

reverse mapped inference annotated parameters partially inferrable noninferrable object context sensitive

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240315#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwGcQNkAHAHgBUBxZWYAgPgAoB9ALngG8AoeeAOZ0YDTr378A2gGl4WfAGsQATxyJ4NYQwC6nZpgAenNAtQ4A7qgA08UrCgBbAp030CM7QEp4AXkbwAIxwcCBAoVABuPngAXyiYzxdaNyieMDwCDEEtAl9CYjJmcWy3MWj+KD1vP3gMGGQQK3LAvVYbOxhHAmr-OoamiXgwVvb7J05UZAcAkBge2vrG6JimhNShNx4Aei34AD0AfiA

💻 Code

declare function setup<TGuards>(_: {
  guards: {
    [K in keyof TGuards]: (ctx: unknown, params: TGuards[K]) => boolean;
  };
}): TGuards;

const guards = setup({
  guards: {
    a: () => true,
    b: (_, params) => true,
    c: (_, params: number) => true,
  },
});

guards
// ^? const guards: { a: unknown; b: unknown; c: unknown; }

🙁 Actual behavior

It infers { a: unknown; b: unknown; c: unknown; }

🙂 Expected behavior

I'd expect { a: unknown; b: unknown; c: number; } to get inferred here

Additional information about the issue

No response

コントリビュヌタヌガむド