Skip to content

v0.6.5: BrowserContext type mismatch due to inlined playwright-core types in bundled .d.mts #45

@ysgk

Description

@ysgk

Description

After upgrading from v0.6.4 to v0.6.5, TypeScript reports a type error when passing @playwright/test's BrowserContext to defineNetworkFixture.

Steps to reproduce

import { test as base } from '@playwright/test'
import { defineNetworkFixture } from '@msw/playwright'

const test = base.extend({
  network: async ({ context }, use) => {
    // TS2322: Type 'BrowserContext' (from @playwright/test) is not assignable
    // to type 'BrowserContext' (inlined in @msw/playwright's bundled types)
    const network = defineNetworkFixture({ context })
    await network.enable()
    await use(network)
    await network.disable()
  },
})

Root cause

The v0.6.5 release (#43) changed the exports conditions. As a result, build/index.d.mts now inlines all of playwright-core's type definitions (~23,000 lines, 1.6MB file).

The source code correctly imports BrowserContext from @playwright/test:

// src/fixture.ts
import type { BrowserContext } from '@playwright/test'

But after bundling with tsdown, this becomes a locally declared BrowserContext interface inside the .d.mts file, rather than a reference to the user's installed @playwright/test types. TypeScript treats these as distinct types, causing the mismatch.

Expected behavior

@playwright/test (or playwright-core) should be marked as external in the tsdown bundle configuration so that the type definition emits an import statement rather than inlining the types.

Environment

  • @msw/playwright: 0.6.5
  • @playwright/test: 1.58.2
  • TypeScript: 5.8.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions