I want to mimic the behavior of the spread operator on types.
so for example type tt = {...{t1:number},t2:number}
=> type tt = {t1:number,t2:number}
Goal: reuse t
t={t1:any; t2:any}
on type tt = { t1:any; t2:any; specific:{t1:any; t2:any} }
, preferably like how { ...t; specific:t }
could have worked (in reality it is much more complex type)
possible solutions:
type tt = { t1:any; t2:any; specific:tt };
- works but nested is allowed unintentionally(tt.specific.t1
is wanted buttt.specific.t1.specfic
is not).another option that does not work.
type t = { t1: any; t2: any;} type tt = { [key in keyof t]: t[key], specific: tt }; // ^ this is not allowed when {[...]:...} is used
Typescript spread operator for type is not a duplicate