Visual Studio Code Deno does not use node types
I'm trying to use the "esquery" node library with its types, but for any reason Deno ignores the type definitions.
File: .vscode/settings.json
File: deno.json
What I did wrong?
General Information:
deno 1.41.3 (release, x86_64-pc-windows-msvc)
v8 12.3.219.9
typescript 5.3.3
Visual Studio Code:
Version: 1.81.1 (user setup)
Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794
Date: 2023-08-09T22:22:42.175Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.19045
Deno Extension:
version: v3.35.1
types/esquery repo: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/esquery
GitHub
DefinitelyTyped/types/esquery at master · DefinitelyTyped/Definitel...
The repository for high quality TypeScript type definitions. - DefinitelyTyped/DefinitelyTyped
3 Replies
Based on the documentation, Deno has its own way of handling TypeScript types, and it does not process a TypeScript configuration file like
tsc
does. Deno only looks at the compilerOptions
section of a configuration file, and even then it only considers certain compiler options, with the rest being ignored.
For packages that don’t distribute types, you can use a @deno-types
directive above the import in order to specify the corresponding @types
package if one exists. However, the types
array you've included in your deno.json
under compilerOptions
is not a supported compiler option in Deno. Instead, you should use the @deno-types
directive directly above the import statement in your TypeScript file.
Here's how you can specify types for a package that doesn't include them:
Make sure that you place the /// <reference types="..." />
directive above the import statement of the module you want to import types for.
Additionally, if you're using Node types, you might need to include a triple-slash reference for Node types as well:
This directive should be placed at the top of your TypeScript file that requires Node types.
If you're still encountering issues, ensure that your Deno settings in Visual Studio Code are correctly configured to enable Deno for your workspace. You can check the current active configuration by using the "Deno: Language Server Status" from the command palette in VSCode.
Lastly, if you're using npm packages and their types, make sure that Deno's compatibility with npm packages is enabled and properly configured in your environment. The documentation mentions that Denowill automatically pull in TypeScript types from npm packages that distribute types, and for those that don't, you can use the
@deno-types
directive as shown above.
If you've followed these steps and are still facing issues, it might be a bug or a case not covered by the documentation, and you may want to search for or report an issue at the vscode_deno repository. 🦕It still does not works