I want to extend the function argument type by adding a function with any name to each object and return it, but i am facing a problem with naming the key of the added function
export type Expand<T> = {
[K in keyof T as K | string ]: T[K] extends { [K in string]: unknown }
? ExpandData<T[K]>
: T[K] | ((p: T) => T);
};
type ExpandData<T extends { [K in string]: unknown }> = T | Expand<T>;
export const create = <T,>(params: Expand<T>): Expand<T> => {
return params;
};
type ICreate = {
param: {
first: {
value: number;
}
}
}
const result = createState<ICreate>({param: {
first: {
value: 1,
change: (val)=> val,
}
}})
// result.param.first.value error
// result.param.first.change error
How to do this correctly?
New contributor
Vitaliy Severniy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.