timkindberg / jest-when

Jest support for mock argument-matched return values.
MIT License
734 stars 38 forks source link

Feature request: support function overloading #62

Closed micalevisk closed 3 years ago

micalevisk commented 3 years ago

Hey!

While using this lib with TypeORM, I'm facing this limitation for function overloading.

Let's say I want to mock a call for repository.findOne method which have 3 overloads. I'll get this:

ts error

since jest-when only recognize the last overload of .findOne which is findOne(conditions?: FindConditions<Entity>, options?: FindOneOptions<Entity>) and I'm using the first one (which is findOne(id?: string|number|Date|ObjectID, options?: FindOneOptions<Entity>)) :confused:

Is there any know workaround for this? Meanwhile I'm using //@ts-expect-error

Great lib btw!

timkindberg commented 3 years ago

Hi @micalevisk Hmm 🤔 I'm not super good at TypeScript and the types are managed over in https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest-when. I've actually not been involved with those at all. I think you'd need to log an issue over there. Perhaps one day we can rewrite this lib in TS, but it won't be soon.