Skip to content

Lost Symbol Reference in LSP for Inferred GenericΒ #61930

Closed
@ivanbanov

Description

@ivanbanov

πŸ”Ž Search Terms

generic, infer, LSP, reference

πŸ•— Version & Regression Information

v5.8.3

⏯ Playground Link

🎒🎒🎒 TS Playground 🎒🎒🎒

πŸ’» Code

type SpecialString = `##${string}`
type Style = { foo?: SpecialString }
export interface StyleFn {
	<T extends Style = Style>(styles: T): T[]
}
const style: StyleFn = (...styles) => styles

style({ foo: '##xx' })  // ❌ hover fails, only the value
style({ foo: '##xx' } satisfies Style) // βœ… hover works
style({ foo: 'xx' }) // βœ… hover works

πŸ™ Actual behavior

When calling a generic function that infers its type argument from an object parameter, the LSP fails to preserve the type reference, even though the typecheck works as expected.

  • Hovering over the property value (someValue) inside the function call does not show the expected type.
  • Go to Definition does not work. TypeScript cannot navigate to the original type definition.
  • If the argument is explicitly asserted with satisfies, or if the line has a type error the reference works.
Image Image

πŸ™‚ Expected behavior

When calling a generic function that infers its type parameter from an object argument, the LSP should preserve type references for all inferred properties, even when no explicit type assertion (like satisfies) is used.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions