NagRock / ts-mockito

Mocking library for TypeScript
MIT License
977 stars 93 forks source link

mock() in 2.4 does not deduce return type from argument #148

Closed dpinol closed 5 years ago

dpinol commented 5 years ago

Hi, first of all, thank you for the implementation of mocks for interfaces in version 2.4.

I see that in v2.4, declaration of mock has changed from

export declare function mock<T>(clazz: {
    new (...args: any[]): T;
} | (Function & {
    prototype: T;
})): T;

to

export declare function mock<T>(clazz?: any): T;

That means the code below is not now correct because the compiler does not know anymore the type of the mock object.

let a = mock(MyClazz)
a.myFunction()

If this changed was done to support interfaces, maybe it makes sense to have 2 different methods? One for mocking classes and one for interfaces? Otherwise, I think at least the change should be documented in the release notes

thanks!

NagRock commented 5 years ago

@dpinol thanks for reporting, will take a look at this.

NagRock commented 5 years ago

Please update to 2.4.2 - should work as expected

dpinol commented 5 years ago

you rock guys! thank you!