Skip to content

Add TypeScript type definitions for package exports#50

Merged
ChALkeR merged 13 commits intomainfrom
copilot/add-typings-for-exports
Feb 2, 2026
Merged

Add TypeScript type definitions for package exports#50
ChALkeR merged 13 commits intomainfrom
copilot/add-typings-for-exports

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Plan: Add TypeScript type definitions for exports

  • Understand repository structure and exports
  • Create type definitions for ./jest export (jest.d.ts)
    • Re-export types from @jest/globals
  • Create type definitions for ./expect export (expect.d.ts)
    • Re-export types from expect package
  • Create type definitions for ./node export (node.d.ts)
    • Re-export types from node:test module (@types/node)
  • Create type definitions for ./mock export (mock.d.ts)
    • Custom types for Exodus-specific APIs
  • Create type definitions for ./tape export (tape.d.ts)
    • Custom types for tape-compatible API
  • Create type definitions for ./benchmark export (benchmark.d.ts)
    • Custom types for benchmark API
  • Update package.json to reference type definitions in exports
  • Update tsconfig.json paths to point to .d.ts files
  • Test TypeScript integration with type checking
  • Fix type definitions to use declare keyword for esbuild compatibility
  • Run linter and format code with prettier
  • Address code review feedback
  • Remove package-lock.json and add to .gitignore (repo uses pnpm)

Key Changes

This PR adds TypeScript type definitions for all package exports by re-exporting from official type packages wherever possible, following the "borrow from jest, node, etc" approach suggested in the issue.

Type Definitions Added

All type definition files now leverage official type definitions from the ecosystem:

  • expect.d.ts (11 lines): Re-exports types from the expect package (existing optionalDependency)
  • jest.d.ts (28 lines): Re-exports types from @jest/globals (existing devDependency)
  • node.d.ts (28 lines): Re-exports types from node:test module (@types/node)
  • mock.d.ts (49 lines): Custom types for Exodus-specific utilities (fetchReplay, websocketRecord, timersSpeedup, etc.)
  • tape.d.ts (154 lines): Custom types for tape-compatible API
  • benchmark.d.ts (35 lines): Custom types for benchmark API

Benefits

  • Reduced maintenance burden: By re-exporting from official packages (expect, @jest/globals, node:test), we avoid maintaining duplicate type definitions
  • Better type accuracy: Official type definitions are maintained by their respective package maintainers
  • Smaller codebase: Total reduction of ~450 lines by leveraging existing types

Only mock.d.ts, tape.d.ts, and benchmark.d.ts contain custom type definitions for library-specific APIs that don't exist in standard packages.

Original prompt

This section details on the original issue you should resolve

<issue_title>typings for exports</issue_title>
<issue_description>can prob "borrow" them from jest, node, etc</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 28, 2026 08:57
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
…ties

Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Copilot AI changed the title [WIP] Add typings for exports from Jest and Node Add TypeScript type definitions for package exports Jan 28, 2026
Copilot AI requested a review from ChALkeR January 28, 2026 09:09
Copy link
Collaborator

@ChALkeR ChALkeR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this repo uses pnpm, don't add package-lock

Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 28, 2026

@copilot this repo uses pnpm, don't add package-lock

Removed package-lock.json and added it to .gitignore in commit 7282e61.

Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Copilot AI and others added 2 commits January 28, 2026 10:30
…ypes/node

Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
@ChALkeR ChALkeR requested a review from Copilot January 28, 2026 10:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds TypeScript type definitions for all package exports, enabling better IDE support and type checking for consumers of the @exodus/test package. The approach leverages official type definitions from ecosystem packages where possible (expect, @jest/globals, node:test) and provides custom types for library-specific APIs.

Changes:

  • Added 6 new .d.ts type definition files covering all package exports (jest, node, tape, expect, mock, benchmark)
  • Updated package.json exports to reference type definitions using the "types" field
  • Updated tsconfig.json paths to point to the new type definition files
  • Added package-lock.json to .gitignore (appropriate since repo uses pnpm)

Reviewed changes

Copilot reviewed 1 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/jest.d.ts Type definitions for Jest-compatible API (has critical issues with runtime exports)
src/node.d.ts Type definitions for Node.js test runner API (has critical issues with runtime exports)
src/tape.d.ts Custom type definitions for tape-compatible testing API
src/expect.d.ts Type re-exports from expect package
src/mock.d.ts Custom types for mocking and testing utilities
src/benchmark.d.ts Custom types for benchmark API (incorrect return type)
package.json Updated exports with "types" field and added .d.ts files to files array
tsconfig.json Updated paths to point to .d.ts files instead of .js files
.gitignore Added package-lock.json (appropriate for pnpm-based project)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChALkeR ChALkeR marked this pull request as ready for review February 2, 2026 21:34
@ChALkeR ChALkeR requested a review from sparten11740 as a code owner February 2, 2026 21:34
@ChALkeR
Copy link
Collaborator

ChALkeR commented Feb 2, 2026

Documentation can be improved later

@ChALkeR ChALkeR requested a review from Copilot February 2, 2026 21:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChALkeR ChALkeR requested a review from Copilot February 2, 2026 23:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChALkeR ChALkeR force-pushed the copilot/add-typings-for-exports branch from 77e1c3c to 767d56d Compare February 2, 2026 23:24
Copy link
Collaborator

@ChALkeR ChALkeR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's land this and improve on top

@ChALkeR ChALkeR merged commit 810ca74 into main Feb 2, 2026
38 checks passed
Comment on lines +11 to +32
export interface BenchmarkOptions {
/** Array of arguments to pass to the benchmark function */
args?: any[]

/** Timeout in milliseconds (default: 1000) */
timeout?: number

/** Skip this benchmark */
skip?: boolean
}

/**
* Runs a benchmark
* @param name - Name of the benchmark
* @param options - Benchmark options
* @param fn - Function to benchmark
*/
export declare function benchmark(
name: string,
options: BenchmarkOptions,
fn: (arg?: any) => any | Promise<any>
): Promise<void>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make this generic over args for type checking of fn against args (or vice versa)

Suggested change
export interface BenchmarkOptions {
/** Array of arguments to pass to the benchmark function */
args?: any[]
/** Timeout in milliseconds (default: 1000) */
timeout?: number
/** Skip this benchmark */
skip?: boolean
}
/**
* Runs a benchmark
* @param name - Name of the benchmark
* @param options - Benchmark options
* @param fn - Function to benchmark
*/
export declare function benchmark(
name: string,
options: BenchmarkOptions,
fn: (arg?: any) => any | Promise<any>
): Promise<void>
export interface BenchmarkOptions<A> {
/** Array of arguments to pass to the benchmark function */
args?: A[]
/** Timeout in milliseconds (default: 1000) */
timeout?: number
/** Skip this benchmark */
skip?: boolean
}
/**
* Runs a benchmark
* @param name - Name of the benchmark
* @param options - Benchmark options
* @param fn - Function to benchmark
*/
export declare function benchmark<A>(
name: string,
options: BenchmarkOptions<A>,
fn: (arg?: A) => any | Promise<any>
): Promise<void>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked the implementation: arg passed to fn is not optional, right? we pass the call count if no args are provided, so we should also accommodate for that in the type:

test/src/benchmark.js

Lines 42 to 45 in b6a9857

const arg = args ? args[count % args.length] : count
count++
const start = getTime()
const val = fn(arg)

Copy link
Collaborator

@ChALkeR ChALkeR Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function can ignore the passed argument
And in many benchmarks, there are no arguments expected by the function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function can ignore the passed argument

it can but that is the point. Functions are contravariant. The function that you provide can accept more general or less parameters than the caller is expected to provide. I.e. you can provide a function that receives no arguments where a function that accepts one parameter is expected.

That also means in our function signature arg should not be optional (marked with a ?). The caller can still pass in a function that accepts no arg based on the contravariance rules

Copy link
Collaborator

@ChALkeR ChALkeR Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sparten11740 I will include the types proposed above, thanks!

*/
export declare const snapshot: {
/** Sets default snapshot serializers */
setDefaultSnapshotSerializers(serializers: any[]): void
Copy link
Contributor

@sparten11740 sparten11740 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we improve on this? any type is no type. I am assuming a serializer is a function that accepts some args (what args?) and returns a string?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 229d4bd.

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

Successfully merging this pull request may close these issues.

typings for exports

4 participants