vscode_deno: Why vs code doesn't show types for Deno

I’ve installed this plugin, but when I try to write code, for example:

console.log(Deno.readDirSync("."));

vs code shows me an error: Cannot find name ‘Deno’.ts(2304) I use built-in version of TypeScript. Do I need to download types somehow?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19

Commits related to this issue

Most upvoted comments

Perhaps init deno will solve the problem: In vscode “show all commands” via CMD/CTRL + SHIFT + P and search for init deno, run it. Helped me to solve all problems with shown errors in vscode with deno.

Hi @buttercubz , @filburt-turle finally, it’s working for me. I downloaded lib.deno.d.ts file, then I restarted the typescript server, restarted mac and it worked! Thanks for the tips 😃

@jbergant as temporary fix you can try to copy lib.deno.d.ts and lib.webworker.d.ts from ~/.vscode/extensions/denoland.vscode-deno-1.24.0/node_modules/typescript-deno-plugin/lib to $HOME/Library/Caches/deno as I mentioned before, but I’m not sure about Mac OS paths you can try. It worked for me on Windows

Fixed by copying lib.deno.d.ts and lib.webworker.d.ts from

C:\Users\<User>\.vscode\extensions\denoland.vscode-deno-1.24.0\node_modules\typescript-deno-plugin\lib

to

C:\Users\<User>\AppData\Local\deno

Seems like extention wasn’t able to copy it’s dts files don’t know why.

I’m running VS Code 1.45.1 on macOS Catalina 10.15.4 using deno: 1.0.5, VS Code’s own typescript server at 3.9.2 and v1.24.0 of the official denoland.vscode-deno plugin and I’m having the same problem.

I tried all the suggestions on this thread including re-downloading the latest lib.deno.d.ts into ~/.vscode/extensions/denoland.vscode-deno-1.24.0/node_modules/typescript-deno-plugin/lib/, restarting the typescript server and rebooting my Mac… to no avail.

However I did find a workaround thanks to this helpful StackOverflow answer. In short:

cd <my-project>
touch tsconfig.json
mkdir lib
deno types > lib/deno_runtime.d.ts 

Even if tsconfig.json is empty, it seems VS Code will automatically include deno_runtime.d.ts. Of course if you put anything else in there, you’ll want to invoke deno with the --config option to ensure it uses your tsconfig.json rather than it’s own.

This worked for me. Cheers!