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

TypeScript Definitions #1

Closed
iFwu opened this issue Nov 16, 2020 · 2 comments
Closed

TypeScript Definitions #1

iFwu opened this issue Nov 16, 2020 · 2 comments

Comments

@iFwu
Copy link
Contributor

iFwu commented Nov 16, 2020

Currently, there are no TypeScript definition files in the package. Is possible to export them?
My global definition for the '@async-fn/jest' package is below:

/// <reference types="jest" />

type AsyncFunction = (...args: any[]) => Promise<unknown>;

type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
	? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
	: Otherwise;

type AsyncReturnType<Target extends AsyncFunction> = PromiseValue<ReturnType<Target>>;

declare module '@async-fn/jest' {
  type MockedAsyncFn<T extends (...args: any[]) => any> =
    & Omit<
      jest.MockInstance<ReturnType<T>, Parameters<T>>,
      | 'mockImplementation'
      | 'mockImplementationOnce'
      | 'mockReturnValue'
      | 'mockReturnValueOnce'
    >
    & T & {
      resolve: (resolvedValue: AsyncReturnType<T>) => Promise<void>,
      reject: (rejectValue: any) => Promise<void>
    };
  export type { MockedAsyncFn };

  export default function asyncFn<T, Y extends any[]>(implementation?: (...args: Y) => T): jest.Mock<T, Y>;
  export default function asyncFn(): jest.Mock;
}
@Iku-turso
Copy link
Collaborator

We'd love to export TypeScript definitions! Let me try pull some strings and hand this over to someone better than me in TypeScript :)

@jansav
Copy link
Collaborator

jansav commented Nov 10, 2021

Minimal TS definitions have been added.

@jansav jansav closed this as completed Nov 10, 2021
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

3 participants