Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing types, i get many ts(2339). #39

Open
Daniele-Tentoni opened this issue Jan 20, 2025 · 1 comment
Open

Missing types, i get many ts(2339). #39

Daniele-Tentoni opened this issue Jan 20, 2025 · 1 comment

Comments

@Daniele-Tentoni
Copy link

Daniele-Tentoni commented Jan 20, 2025

Running npm run build on my project fire many of those errors:

src/stores/__tests__/pin.spec.ts:72:20 - error TS2339: Property 'requests' does not exist on type '{ (input: URL | RequestInfo, init?: RequestInit | undefined): Promise<Response>; (input: string | URL | Request, init?: RequestInit | undefined): Promise<...>; }'.   

72       expect(fetch.requests().length).toEqual(1);

I cannot add to my tsconfig.json types because of Cannot find type definition file for 'vitest-fetch-mocks'.:

{
  "extends": "./tsconfig.app.json",
  
  "exclude": [],
  "compilerOptions": {
    "composite": true,
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.vitest.tsbuildinfo",

    "lib": [],
    "types": ["node", "jsdom", "vitest-fetch-mocks"]
  }
}

The solution was to add an ignore comment before every line:

// @ts-expect-error vitest-fetch-mock missing types.
expect(fetch.requests().length).toEqual(1);

Do you have same errors?

My env is composed as follow:

{
  "type": "module",
  "scripts": {
    "build": "run-p type-check \"build-only {@}\" --",
    "build-only": "vite build",
    "type-check": "vue-tsc --build --force",
  },
  "devDependencies": {
    "@tsconfig/node20": "^20.1.4",
    "@types/jsdom": "^21.1.7",
    "@types/node": "^20.17.4",
    "@vitejs/plugin-vue": "^5.1.4",
    "@vitest/coverage-v8": "^2.1.8",
    "@vitest/eslint-plugin": "1.1.7",
    "@vue/eslint-config-prettier": "^10.0.0",
    "@vue/eslint-config-typescript": "^14.1.1",
    "@vue/test-utils": "^2.4.6",
    "@vue/tsconfig": "^0.5.1",
    "cypress": "^13.15.0",
    "eslint": "^9.13.0",
    "eslint-plugin-cypress": "^4.0.0",
    "eslint-plugin-vue": "^9.29.0",
    "jsdom": "^25.0.1",
    "npm-run-all2": "^7.0.1",
    "prettier": "^3.3.3",
    "resize-observer-polyfill": "^1.5.1",
    "start-server-and-test": "^2.0.8",
    "typescript": "~5.6.0",
    "vite": "^5.4.10",
    "vite-plugin-vue-devtools": "^7.5.3",
    "vitest": "^2.1.8",
    "vitest-fetch-mock": "^0.4.3",
    "vue-tsc": "^2.1.6"
  }
}

I setup my tests using:

    test: {
      setupFiles: [
        "./__tests__/setup.ts"
      ]
    }

And my setup contains:

import createFetchMock from 'vitest-fetch-mock';
import { vi } from 'vitest';

const fetchMocker = createFetchMock(vi);

// sets globalThis.fetch and globalThis.fetchMock to our mocked version
fetchMocker.enableMocks();

I have omitted any non relevant informations from my package.json I think, let me know if i have to provide other info.

@IanVS
Copy link
Owner

IanVS commented Jan 21, 2025

Thanks for the report. Would you mind creating a new repository with a minimal reproduction of the issue you're seeing here, so that we can clone it and investigate?

However, one thing I do notice is that you've got a typo in your tsconfig.json. The name of the package is vitest-fetch-mock not vitest-fetch-mocks.

That said, I wouldn't expect you to have to add anything to types, since everything in node_modules usually will be picked up automatically, unless you change typeRoots. So yeah, I think we'd need a reproduction to investigate further.

@IanVS IanVS pinned this issue Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants