Skip to content

Some long function return expressions no longer evaluated in 5.5Β #58937

Closed
@ssalbdivad

Description

@ssalbdivad

πŸ”Ž Search Terms

function return type inferred isolatedDeclarations regression

πŸ•— Version & Regression Information

This changed occurred as a result of 2b4e7e34e7a40fe0d886aec6f799954420f2ac0c (#58546)

⏯ Playground Link

https://tsplay.dev/WY7ZbN

πŸ’» 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.

Metadata

Metadata

Assignees

Labels

Domain: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoFix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions