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
I have really no idea how to call this helper, but let me describe the use case.
// Lets imagine I have an options typetypeOptions{readOnly?: boolean;
required?: boolean;
filters?: Record<string,string>;// ...}// Now lets see how I can use in a functionconstbuildOptions(required: boolean,name: string,team?: string)=>{constoptions: Options={
required,filters: {
name,},};if(team){// Issue is that filters even if defined above remains optional/partialoptions.filters.team=team;}}// Today we could manuall build the correct type asconstoptions: Options&Pick<Required<NonNullable<Options>>,'required'|'filters'>={...}// Issue is when adding more property you always need to add the property in the list// I tried the following without success to infer the type without explicitely giving the keysexportconstmakeInferredPartial=<Base,RealextendsRequired<NonNullable<Base>>>(// partial: {[Key in keyof Base]: Required<NonNullable<Base>>[Key]} extends infer Return ? Partial<Base> & Return : never,partial: Real,)=>partial;constoptions=makeInferredPartial<Options>({filters: {name: 'Hello world'},})// Would expect the type to be like{readOnly?: boolean;
required?: boolean;
filters: Record<string,string>;// Note it become defined// ...}// Then the following worksoptions.filters.team='admin';
Please let me know if that make sense and if you could help me to build this helper. I think this become pretty useful when the type has plenty of props and you just want to define them and infer the correct typing.
Thanks in advance for your help.
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
The funding will be given to active contributors.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
I have really no idea how to call this helper, but let me describe the use case.
Please let me know if that make sense and if you could help me to build this helper. I think this become pretty useful when the type has plenty of props and you just want to define them and infer the correct typing.
Thanks in advance for your help.
Upvote & Fund
The text was updated successfully, but these errors were encountered: