2

I am following this document to run a hello-world typescript program in Visual Studio Code Editor.

I have done following steps

  1. Installed the TypeScript compiler tsc --version shows Version 4.2.4
  2. Transpiled TypeScript into JavaScript

When i try to run the type script build, by Executing Run Build Task (⇧⌘B) I DONOT see any task to build in that.

enter image description here

So I am stuck at this point. Can some one tell me if we need to manually create this task? OR is there a pre-requisite that I am missing?

Thanks!

2
  • Have you tried restarting Visual Studio Code Commented May 16, 2021 at 12:41
  • @MrCodingB Yes, I did restart, but no relief Commented May 16, 2021 at 12:50

1 Answer 1

3

Try restarting VSCode. If that doesn't work try configuring the task via:

Command palette (Ctrl+Shift+P / F1) > Tasks: Configure default build task

If that doesn't work here are the default task configurations:

{
    "version": "2.0.0",
    "tasks": [
        {  // For build
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ],
            "group": "build",
            "label": "tsc: build - tsconfig.json"
        },
        {  // For watch
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "option": "watch",
            "problemMatcher": [
                "$tsc-watch"
            ],
            "group": "build",
            "label": "tsc: watch - tsconfig.json"
        },
        { // If both of the above don't work you could create an npm script and run it via this task
            "type": "npm",
            "script": "build", // This should be the name of your script
            "problemMatcher": [],
            "label": "npm: build typescript"
        }
    ]
}

For these to be detected create a .vscode Folder at the root of your workspace and create a file tasks.json in it. If you put the above json in it, VSCode will find your tasks.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, can you please also explain a bit where and how to use default task configurations.
Added a little explanation to my answer
Thanks so much. A minor suggestion Please also open the command to open the command pallet. Ctrl+Shift+P will bring you directly to the editor commands. I just ran the command you mentioned and was able to build. Thanks!
Those first two tasks only work right (on WIndows) if VS Code is using the Windows command line interpreter as the shell. The tsc.js script detects the OS it's running on and sets the path separator to match it. If you are using a Unix shell, like bash, the path characters disappear into the command and won't find the command being executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.