-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 3.2.2
Search Terms:
Code
It is a common situation that provides some default params to required options and make them be optional to bring convenient calling usage.
interface HasHeight {
height: number
}
type Omit<P, K extends keyof P> = Pick<P, Exclude<keyof P, K>>
function makeHeightOptional<P extends HasHeight>(heightRequired: (p: P) => number) {
return function heightOptional(params: Omit<P, 'height'> & { height?: number }) {
const height = params.height || 10
const newParams = { ...params, height }
// Argument of type 'Pick<P, Exclude<keyof P, "height">> & { height: number; }' is not assignable to parameter of type 'P'.
return heightRequired(newParams)
}
}
Expected behavior:
code works
Actual behavior:
TS report:
Argument of type 'Pick<P, Exclude<keyof P, "height">> & { height: number; }' is not assignable to parameter of type 'P'.
Related Issues:
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created