Add TypeScript type definitions for package exports#50
Conversation
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>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
…ypes/node Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
There was a problem hiding this comment.
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.tstype 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.
|
Documentation can be improved later |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
77e1c3c to
767d56d
Compare
ChALkeR
left a comment
There was a problem hiding this comment.
Let's land this and improve on top
| 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> |
There was a problem hiding this comment.
We could make this generic over args for type checking of fn against args (or vice versa)
| 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> |
There was a problem hiding this comment.
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:
Lines 42 to 45 in b6a9857
There was a problem hiding this comment.
The function can ignore the passed argument
And in many benchmarks, there are no arguments expected by the function
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@sparten11740 I will include the types proposed above, thanks!
| */ | ||
| export declare const snapshot: { | ||
| /** Sets default snapshot serializers */ | ||
| setDefaultSnapshotSerializers(serializers: any[]): void |
There was a problem hiding this comment.
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?
Plan: Add TypeScript type definitions for exports
./jestexport (jest.d.ts)./expectexport (expect.d.ts)./nodeexport (node.d.ts)./mockexport (mock.d.ts)./tapeexport (tape.d.ts)./benchmarkexport (benchmark.d.ts)declarekeyword for esbuild compatibilityKey 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:
expectpackage (existing optionalDependency)@jest/globals(existing devDependency)node:testmodule (@types/node)Benefits
expect,@jest/globals,node:test), we avoid maintaining duplicate type definitionsOnly
mock.d.ts,tape.d.ts, andbenchmark.d.tscontain custom type definitions for library-specific APIs that don't exist in standard packages.Original prompt
💡 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.