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

typescript .vue file include @types/node when include some package #500

Closed
ZurrTum opened this issue Apr 23, 2024 · 2 comments
Closed

typescript .vue file include @types/node when include some package #500

ZurrTum opened this issue Apr 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ZurrTum
Copy link

ZurrTum commented Apr 23, 2024

Describe the bug

When I introduce certain packages, for example: socket.io-client
Or vite in the picture
setTimeout return NodeJS.Timeout
image

Expected behavior

setTimeout return number
image

How to reproduce

  1. npm create vue@latest
  2. typescript yes
  3. cd vue-project && npm install
  4. using vscode open App.vue
  5. check setTimeout return type is number
  6. import some package e.g.: vite
  7. check setTimeout return type is NodeJS.Timeout

tsconfig.json (default)

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.node.json"
    },
    {
      "path": "./tsconfig.app.json"
    }
  ]
}

tsconfig.app.json (default)

{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "composite": true,
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",

    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}
@ZurrTum ZurrTum added the bug Something isn't working label Apr 23, 2024
@cexbrayat
Copy link
Member

Hi @ZurrTum

I don't think this is an issue with create-vue. If you're using https://github.com/vuejs/language-tools you can maybe open an issue there with a reproduction and check if this is not an issue with the VS Code extension.

@ZurrTum
Copy link
Author

ZurrTum commented Apr 23, 2024

Supplement, if anyone encounters:
/// <reference types="node" />
Node module dependencies that use a triple-slash directive to reference libs poison the global scope  #33111

Imperfect solution

tsconfig.app.json only, include vite.config.ts, declare node:url

env.d.ts

/// <reference types="vite/client" />
declare module "node:url" {
  class URL {
    constructor(
      input: string | { toString: () => string },
      base?: string | URL
    );
  }
  function fileURLToPath(url: string | URL): string;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants