You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code
It is a common situation that provides some default params to required options and make them be optional to bring convenient calling usage.
interfaceHasHeight{height: number}typeOmit<P,KextendskeyofP>=Pick<P,Exclude<keyofP,K>>functionmakeHeightOptional<PextendsHasHeight>(heightRequired: (p: P)=>number){returnfunctionheightOptional(params: Omit<P,'height'>&{height?: number}){constheight=params.height||10constnewParams={ ...params, height }// Argument of type 'Pick<P, Exclude<keyof P, "height">> & { height: number; }' is not assignable to parameter of type 'P'.returnheightRequired(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'.
Activity
jack-williams commentedon Dec 17, 2018
Think this is a duplicate of #28884
ahejlsberg commentedon Dec 17, 2018
Duplicate of #28884.
typescript-bot commentedon Dec 20, 2018
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.