martpet
martpet4mo ago

Plain javascript in .js files in vscode

How can I have DOM suggestions in .js files, while having Deno suggestions in .ts files?
2 Replies
Deno AI Helper
Deno AI Helper4mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, regarding your question about having DOM suggestions in .js files and Deno suggestions in .ts files within Visual Studio Code, this typically involves configuring your editor to understand the context in which you're working. For Visual Studio Code, you might want to look into configuring your workspace settings to differentiate between .js and .ts files. One way to approach this could be to use the deno.enable setting in your settings.json file for your workspace. You can enable Deno for TypeScript files and leave it disabled for JavaScript files, which might look something like this:
{
"[typescript]": {
"deno.enable": true
},
"[javascript]": {
"deno.enable": false
}
}
{
"[typescript]": {
"deno.enable": true
},
"[javascript]": {
"deno.enable": false
}
}
This way, VS Code might provide DOM suggestions for .js files using its default JavaScript language features and Deno suggestions for .ts files when the Deno extension is enabled. Please note that this advice is not based on the Deno documentation, and I would recommend double-checking the accuracy of this advice and looking into the documentation or community resources for Visual Studio Code and the Deno VS Code extension for more detailed guidance.
CodyC
CodyC4mo ago
You may already know, but to tell deno to allow (and autocomplete) DOM types, you'll need to add "dom" to compilerOptions.lib in deno.json[c]. See: https://docs.deno.com/runtime/manual/advanced/typescript/configuration#using-the-lib-property Unfortunately, these compiler options seem to be project-wide, even if you specify them with triple-slash directives in individual files. The only way I've seen to have separate rules for separate files is to make them separate deno projects.