-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolutionHelp WantedYou can do thisYou can do this
Milestone
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
π» 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.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolutionHelp WantedYou can do thisYou can do this