Skip to content

bun.d.ts is currently broken #674

@alii

Description

@alii

Hi 👋 Bun engineer here

We had a bug report that the matcher types were not automatically loaded when using jest-dom. I took a look in the type definitions and noticed that the bun.d.ts file is currently erroring.

The error is that the Matchers interface isn't compatible with the one declared in @types/bun:

Image

The fix is to default the type parameter to unknown.

import { type TestingLibraryMatchers } from './matchers';

declare module 'bun:test' {
  interface Matchers<T = unknown>
    extends TestingLibraryMatchers<
      ReturnType<typeof expect.stringContaining>,
      T
    > {}
}

This is also a good opportunity to remove the export {} and the unused import from bun:test. The bun:test import can be removed because TypeScript looks up symbols inside of a module block first before the parent scope, so expect actually already exists in this scope. The export {} is unnecessary because the import statement already makes this ambient declaration file a module.

Lastly, I couldn't find documentation on if usage of the bun.d.ts file is recommended, but in theory if the bun.d.ts is fixed then we could recommend in our guides that the best way to load the types into bun:test is with a triple slash reference like this:

/// <reference path="./node_modules/@testing-library/jest-dom/types/bun.d.ts" />

However since there's no mention of using bun.d.ts in the jest-dom readme, we could instead recommend in our guides that users copy & paste the declaration into their projects themselves, and then maybe bun.d.ts could be removed from jest-dom.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions