Microsoft/TypeScript

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

Open

#57 788 ouverte le 15 mars 2024

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
Domain: Mapped TypesHelp WantedPossible Improvement

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

🔎 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

Guide contributeur