-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Bug Report
π Search Terms
circular type parameter constraint
π Version & Regression Information
Tested with 4.8.4
β― Playground Link
π» Code
declare const f:
<T extends F<T>>(t: T) => T
type F<T> =
{ a: unknown
, b: (a: T extends { a: infer X } ? X : never) => unknown
}
f({
a: "hello",
b: x => x.toUpperCase()
})
// doesn't compile because infers `x` as `unknown` instead of `string`
f({
a: "hello",
b: (x: string) => x.toUpperCase()
})
// compilesNote that there is a workaround but it's only a workaround for this minimal case and not for the real world case from which this minimal case was derived.
π Actual behavior
x in the first f call gets inferred as unknown
π Expected behavior
x in the first f call should get inferred as string
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript