microsoft / microsoft/TypeScript

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

Aperta
#61,516 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: check: Type Inference Help Wanted
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

### 🔎 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

```ts
type Obj =
| { type: 'a', id: string, a: string }
| { type: 'b', id: string, b: number };

interface API {
works(
obj: T,
): void;

alsoWorks(
obj: Pick,
): void;

alsoAlsoWorks(
obj: Partial
): void;

doesntWork(
obj: Pick & Partial
): void;
}

type WorksParams = Parameters; // [obj: Obj]
type AlsoWorksParams = Parameters; // [obj: Pick]
type AlsoAlsoWorksParams = Parameters; // [obj: Partial]
type DoesntWorkParams = Parameters; // never
```

### 🙁 Actual behavior

`Parameters` returns `never`

### 🙂 Expected behavior

The `Parameters` case behaves like the other cases and returns `[obj: Pick & Partial]`.

### 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`](https://www.electronjs.org/docs/latest/api/ipc-main#ipcmainhandlechannel-listener) method. If anyone knows of a workaround for this `Parameters` problem, I'd love to hear it.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il TypeScript Playground collegato e riduci l'esempio di API che coinvolge Pick & Partial. Confronta i risultati di Parameters per i quattro metodi e traccia il comportamento rilevante dell'inferenza dei tipi. Il lavoro è completato quando il caso combinato di Pick e Partial produce la tupla dei parametri prevista senza regressioni negli altri casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.