Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Typescript type fixes #2835

Merged
merged 2 commits into from
Sep 13, 2024
Merged

Typescript type fixes #2835

merged 2 commits into from
Sep 13, 2024

Conversation

jesstelford
Copy link
Contributor

  • Correctly type the mock function's return value
  • Remove "@babel/traverse" dependency

Used only as types which are also available from @babel/core. This
ensures the types don't get out of sync since @babel/core is sometimes
listed as a peer dependency (web-worker).
@jesstelford jesstelford marked this pull request as ready for review September 12, 2024 08:43
@jesstelford jesstelford requested a review from a team as a code owner September 12, 2024 08:43
@@ -112,5 +112,5 @@ export default function createContext<
context.request.body = requestBody;
context.request.rawBody = rawBody;

return context as Context;
return context as MockContext;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Context is a subset of MockContext, so this should be structurally backwards compatible.

types as babelTypes,
template as babelTemplate,
} from '@babel/core';

import type {Options as LoaderOptions} from './webpack-parts/loader';

type Binding = BabelFile['scope']['bindings'][string];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary to avoid an error under certain circumstances when the version of @babel/traverse is incompatible with the peer dependency @babel/core:

packages/web-worker/src/babel-plugin.ts(118,26): error TS2345: Argument of type 'Binding' is not assignable to parameter of type 'Binding'.

Investigating reveals node_modules/@types/babel__traverse to be version 7.11.1, but node_modules/@types/babel__core/node_modules/@types/babel__traverse is 7.20.1, which is where the conflicting versions of Binding come from.

@jesstelford jesstelford merged commit 209a11f into main Sep 13, 2024
5 checks passed
@jesstelford jesstelford deleted the type-fixes branch September 13, 2024 04:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants