Warlockk
Warlockk9mo ago

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
{
"deno.enable": true
}
{
"deno.enable": true
}
File: deno.json
{
"version": "1.0",
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"node:esquery": "npm:esquery"
},
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"types": [
"npm:@types/esquery/index.d.ts"
]
}
}
{
"version": "1.0",
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"node:esquery": "npm:esquery"
},
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"types": [
"npm:@types/esquery/index.d.ts"
]
}
}
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
No description
3 Replies
Deno AI Helper
Deno AI Helper9mo ago
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:
/// <reference types="npm:@types/esquery" />
import * as esquery from "npm:esquery";
/// <reference types="npm:@types/esquery" />
import * as esquery from "npm:esquery";
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:
/// <reference types="npm:@types/node" />
/// <reference types="npm:@types/node" />
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 Deno
Deno AI Helper
Deno AI Helper9mo ago
will 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. 🦕
Warlockk
WarlockkOP9mo ago
It still does not works