I read this article on how to run a typescript file on the command line, and it appears to be working, but VS Code is reporting invalid errors:
You can see from the terminal (bottom half of the picture) that this file runs without issue. According to the lower right-hand corner, VS Code recognizes the file as typescript, but it doesn't recognize any libraries in its environment.
Perhaps it thinks this is configured for web instead of node? I do have evidence for that: it auto-completes the contents of window
and document
. Is there some way I can tell VS Code that this is a node environment?
It's worth noting that VS Code is running in an Ubuntu WSL terminal/environment on Windows 10. There is no tsconfig.json
file involved. It's using whatever's the default. This "script" sits in my personal /bin
directory alongside other bash shell scripts. As such, I'm trying to avoid all the boilerplate of setting up an entire TS project to get this working.
Update: That error on fs
suggested a "Quick Fix" to install node types. I ran npm i --save-dev @types/node
and the error went away, but it created a "node_modules" directory. Since "node_modules" doesn't seem necessary to execute the script, and since it will be used by the next ts shell script I put in that bin/
directory, I'm hoping there is another solution.
I'm trying to avoid creating a project / node_module dir / tsconfig.json / etc. to solve this as my intent is to write a shell script in typescript instead of bash. One of the benefits of shell scripts is you can just create a file and run it; you don't need much, if any, boilerplate.