stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.53k stars 240 forks source link

Compilation error Type 'FetchMockSandbox' is not assignable #2241

Closed LukeMccon closed 2 years ago

LukeMccon commented 2 years ago

Describe the bug When running yarn test on the latest develop branch (05ee443) I am receiving the error below

ERROR [compiler.karma-typescript]: packages/ruleset-migrator/src/__tests__/ruleset.test.ts(142,9): error TS2322: Type 'FetchMockSandbox' is not assignable to type 'Fetch | undefined'.
  Type 'FetchMockSandbox' is not assignable to type '(uri: string, opts?: RequestInit) => Promise<Response>'.
    Types of parameters 'init' and 'opts' are incompatible.
      Type 'import("/mnt/c/Users/Luke/Documents/Development/spectral/node_modules/@types/node-fetch/index").RequestInit | undefined' is not assignable to type 'RequestInit | undefined'.
        Type 'import("/mnt/c/Users/Luke/Documents/Development/spectral/node_modules/@types/node-fetch/index").RequestInit' is not assignable to type 'RequestInit'.
          Types of property 'body' are incompatible.
            Type 'BodyInit | undefined' is not assignable to type 'BodyInit | null | undefined'.
              Type 'ReadableStream' is not assignable to type 'BodyInit | null | undefined'.

15 08 2022 00:28:37.969:INFO [compiler.karma-typescript]: Compiled 385 files in 16628 ms.
15 08 2022 00:28:37.971:ERROR [karma-server]: Error during file loading or preprocessing
undefined
15 08 2022 00:28:37.972:INFO [karma-server]: Karma v6.4.0 server started at http://localhost:9876/
15 08 2022 00:28:37.972:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
15 08 2022 00:28:37.996:INFO [launcher]: Starting browser ChromeHeadless
15 08 2022 00:28:38.135:INFO [Chrome Headless 104.0.5112.79 (Linux x86_64)]: Connected on socket QJPYGbSzQTZngoupAAAB with id 60342506
Chrome Headless 104.0.5112.79 (Linux x86_64) ERROR
  You need to include some adapter that implements __karma__.start method!

To Reproduce

  1. run yarn test on develop (05ee443)
  2. Observe compilation error

Expected behavior TS compiles, tests pass

Environment:

P0lip commented 2 years ago

That is weird since it doesn't occur both on my end as well as CI. Did you try removing all node_modules and re-installing?

LukeMccon commented 2 years ago

That is weird since it doesn't occur both on my end as well as CI. Did you try removing all node_modules and re-installing?

yes I removed all the node_modules and reinstalled them. I found out what was happening, yarn was resolving typescript ^4.4.4 as typescript 4.7.4 which was giving the error. Manually downgrading to 4.4.4 seems to fix the issue