Description
π Search Terms
function return type inferred isolatedDeclarations regression
π Version & Regression Information
This changed occurred as a result of 2b4e7e34e7a40fe0d886aec6f799954420f2ac0c
(#58546)
β― Playground Link
π» Code
/** This is the minimal version which seems somewhat innocuous */
export type inferPipe<t, pipe> =
pipe extends (In: t) => unknown ? (In: t) => ReturnType<pipe> : never
interface Type<t> {
pipe<fn extends (In: t) => unknown>(fn: fn): Type<inferPipe<t, fn>>
}
declare const t: Type<string>
// Before: Type<(In: string) => number>
// 2b4e7e34e7a40fe0d886aec6f799954420f2ac0c
// After: Type<(In: string) => ReturnType<(s: string) => number>>
const out = t.pipe(s => parseInt(s))
/** In ArkType and in other cases where these expressions are used as part of a deeper type,
* it can lead to hovers growing exponentially in size as expressions are chained
* instead of being evaluted at each step and staying the same.
*
* Here's an example of what occurs with a longer expression
* */
export type inferPipe2<t, pipe> =
pipe extends (In: t) => unknown ?
(In: t) => ReturnType<pipe> extends infer n extends number ? n
: ReturnType<pipe> extends infer s extends string ? s
: ReturnType<pipe> extends infer b extends boolean ? b
: never
: never
interface Type2<t> {
pipe<fn extends (In: t) => unknown>(fn: fn): Type2<inferPipe2<t, fn>>
}
declare const t2: Type2<string>
// Before: Type2<(In: string) => number>
// 2b4e7e34e7a40fe0d886aec6f799954420f2ac0c
// After: Type2<(In: string) => ReturnType<(s: string) => number> extends infer n extends number ? n : ReturnType<(s: string) => number> extends infer s extends string ? s : ReturnType<(s: string) => number> extends infer b extends boolean ? b : never>
const out2 = t2.pipe(s => parseInt(s))
π Actual behavior
Trivially evaluated ReturnType
not evaluated on hover.
π Expected behavior
It should be evaluated
Additional information about the issue
The example from the playground can worked around by inferring a variable in the position of unknown
to get the return type directly instead of using the ReturnType
alias.
This causes a massive regression in the quality of hover displays for many types in ArkType, which I'm still working to determine if can be avoided as-is.
If the team does decide it wants to address this, it would be a huge relief to me to know so I can avoid trying to find workarounds that may involve changing significant parts of the code base to have hovers that were previously a couple dozen characters long be remotely readable after 5.5.