Microsoft/TypeScript
Voir sur GitHubNoInfer not working on callback parameter destructuring
Open
#60 544 ouverte le 20 nov. 2024
Domain: check: Type InferenceHelp 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
NoInfer parameter callback destructuring
🕗 Version & Regression Information
Latest to date.
⏯ Playground Link
💻 Code
class Foo<T, R> {
constructor(readonly cb: (t: T, _: NoInfer<{ x: number; other: NoInfer<R> }>) => R) {}
}
const _1 = new Foo((name: string, { x }) => ({ name, x })); // Foo<string, unknown>
// should be Foo<string, { name: string; x: number }>
const _2 = new Foo((name: string) => ({ name })); // works: Foo<string, { name: string }>
🙁 Actual behavior
infers unknown.
🙂 Expected behavior
Should ignore the parameter tagged with NoInfer and infer correctly.
Additional information about the issue
Is this intended behavior? feels like a bug to me.
If the callback parameter is destructured partially it infers unknown, but it works if the parameter is omitted.
I tried NoInfer at various locations.