Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsafe Argument matchers due to return any #38

Open
ratoaq2 opened this issue Jul 15, 2023 · 1 comment
Open

Unsafe Argument matchers due to return any #38

ratoaq2 opened this issue Jul 15, 2023 · 1 comment

Comments

@ratoaq2
Copy link

ratoaq2 commented Jul 15, 2023

When trying to enable the recommended-type-checked from typescript eslint, I found out that most of ts-mockito argument matchers are actually unsafe since most of them returns any, which completely disables type checking.

An example of a common violated rule when using argument matchers, is no-unsafe-argument

Probably, returning any should be avoided for all argument matchers. Here's a suggestion that I'm evaluating:

export declare function anyOfClass<T>(expectedClass: new (...args: any[]) => T): T;
export declare function anyFunction(): Function;
export declare function anyNumber(): number;
export declare function anyString(): string;
export declare function anything<T>(): T;
export declare function between(min: number, max: number): number;
export declare function deepEqual<T>(expectedValue: T): T;
export declare function notNull<T>(): T;
export declare function strictEqual<T>(expectedValue: T): T;
export declare function match(expectedValue: RegExp | string): string;
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
export declare function objectContaining<T extends Object, V extends Optional<T, keyof T>>(expectedValue: V): T;
@roypeled
Copy link
Collaborator

Good idea, here is the PR: #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants