microsoft / microsoft/TypeScript

`Parameters` returns `never` when used with a generic function that combines `Pick` and `Partial` on the generic type argument

Open
#61,516 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: check: Type Inference Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms

partial pick generic parameters never

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Parameters
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250331#code/C4TwDgpgBA8gRgKygXgFBSgHygbyqSALigHIBDEgGigEsATYgZ2ACcaA7Ac2rKdY85QAvuiy584CMRJwqtBlGZsu1OMXYBXALZwILYQG5UqDsD0AzMgGNoAQQAKASVyiA7gHsWAa0YAeACpQEAAeZux0jLCIAHwAFKIY7ojE-pSiAJTEAG7u9EaiZAA2jO4A6p4+AUGhEOGR8AhxCVBJCMT2NFZeAdQkBBAkYiT0JNFpGJlQOXnGGEUltsVlFX6BIWERUY3xGInJUPZkLMA0RQHRGdm5dPkYdO4QjOzA5d5V67WbDU27LfsdXR6pH6g2wwzooygADIDkcTmd-BcJlcZiJUP0oK8fIcWGQtJFkLDcVoIGYWH4HI4ANokDzeRgkAC60QMvzZ7IwAHpOVAqa1iA1GejJFBFiUsYwcXiCUS8aS9BSnDT5st6UyWRyuTy+f9Ot0GtQAET9Q1iQ30Q3RIUYsXuW0SqX4lCyklkxXU8hLe0rdWs7m8-lE+GFXzfa0igAiDyeLwqjpljvl5N8lJp90ezyxvo5-vYECyeiAA

💻 Code
type Obj =
  | { type: 'a', id: string, a: string }
  | { type: 'b', id: string, b: number };

interface API {
  works<T extends Obj>(
    obj: T,
  ): void;

  alsoWorks<T extends Obj>(
    obj: Pick<T, 'type' | 'id'>,
  ): void;

  alsoAlsoWorks<T extends Obj>(
    obj: Partial<T>
  ): void;

  doesntWork<T extends Obj>(
    obj: Pick<T, 'type' | 'id'> & Partial<T>
  ): void;
}

type WorksParams = Parameters<API['works']>;                 // [obj: Obj]
type AlsoWorksParams = Parameters<API['alsoWorks']>;         // [obj: Pick<Obj, "type" | "id">]
type AlsoAlsoWorksParams = Parameters<API['alsoAlsoWorks']>; // [obj: Partial<Obj>]
type DoesntWorkParams = Parameters<API['doesntWork']>;       // never
🙁 Actual behavior

Parameters<API['doesntWork']> returns never

🙂 Expected behavior

The Parameters<API['doesntWork']> case behaves like the other cases and returns [obj: Pick<Obj, "type" | "id"> & Partial<Obj>].

Additional information about the issue

I'm not sure why Parameters works for all cases except when Pick and Partial are used together. I'm having the same problem when using extends and infer to get the parameters.

My use case is to prepend an argument event: IpcMainInvokeEvent to several generic functions to match the signature expected by the listener argument of Electron's ipcMain.handle method. If anyone knows of a workaround for this Parameters problem, I'd love to hear it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground and reduce the API example involving Pick<T, 'type' | 'id'> & Partial. Compare the Parameters results for the four methods and trace the relevant type-inference behavior. Done means the combined Pick and Partial case produces the expected parameter tuple without regressing the other cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.