bwgjoseph / mongoose-vs-ottoman

feature comparison between mongoose and ottoman
0 stars 1 forks source link

generics for IModel #83

Open bwgjoseph opened 3 years ago

bwgjoseph commented 3 years ago

Hi,

As mentioned in #71, (maybe it was overlooked) but I'm wondering if this is better? Is there any cons to using <T = any, R = T> vs <T = any, R = any>?


I suppose if changing the declaration to something like this would be much better

interface IModel<T = any, R = T>

By default, R takes T which will be any if the type is not defined which is essentially the same as

interface IModel<T = any, R = any>

So this would also be changed to something like

// from
replaceById<Doc = T, Result = R>(id: string, data: Doc | Document<Doc>, options?: MutationFunctionOptions): Promise<Result>;

// to
replaceById<Doc = T, Result = Doc>(id: string, data: Doc | Document<Doc>, options?: MutationFunctionOptions): Promise<Result>;

So if it was declared individually T = any, R = any or Doc = T, Result = R

then it would be like this where return type doesn't get auto inferred from T and default to any

image

But if I were to change, then T and R is basically the same if R is not defined

image

Thanks