#Paid assistance
9 messages · Page 1 of 1 (latest)
i don't think you need overloads for this since you have all those defaults
or maybe you do, let's see
yeah probably to prevent some other issues
i don't think you can really make this typesafe actually
at least in the implementation
Preview:ts ... function array2Tree<Id extends string | number, T extends Record<'id', Id> & Record<'pid', Id>>(data: T[]): T; function array2Tree<Id extends string | number, T extends Record<KId, Id> & Record<'pid', Id>, const KId extends string>(data: T[], idField: KId): T; function array2Tree<Id extends string | number, T extends Record<KId, Id> & Record<KPId, Id>, const KId extends string, const KPId extends string>(data: T[], idField: KId, parentIdField: KPId): T; function array2Tree<Id extends string | number, T extends Record<KId, Id> & Record<KPId, Id>, const KId extends string, const KPId extends string, const KChildren extends string>(data: T[], idField: KId, parentIdField: KPId, childrenField: KChildren): T; ...
managed to get this but the inference doesn't work so well
Thanks much, but there may be a deviation in my description. Using function overloading is just one of the means, and it is also possible to avoid using function overloading. Sorry again about the payment, because this problem has been bothering me, I just hope to find a better solution as soon as possible