Microsoft/TypeScript

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

Open

#57.788 geöffnet am 15. März 2024

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Domain: Mapped TypesHelp WantedPossible Improvement

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔎 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

Contributor Guide