×
☰ See All Chapters

Typescript tsconfig.json Example

In this tutorial we execute the sample TypeScript code by setting tsc configurations in tsconfig.json. Before proceeding to execute this example you should have TypeScript execution environment to convert TypeScript to JavaScript. Please refer our previous tutorial Typescript Environment Setup and make sure you have ready environment.

Project structure

typescript-tsconfig-json-example-0
 

welcome.ts

class HelloTS {

  public printMessage() {

    document.write("Hello TypeScript!");

  }

}

let hello: HelloTS = new HelloTS();

hello.printMessage();

welcome.html

<!DOCTYPE html>

<html>

    <body>

        <script src="../js/welcome.js"></script>

    </body>

</html>

tsconfig.json

{

        "include": [

                "WebContent/WEB-INF/ts/*"

        ],

        "compilerOptions": {

                "noEmitOnError": true,

                "outDir": "WebContent/WEB-INF/js"

        }

}

Open command prompt/terminal for the directory having tsconfig.json and run tsc

typescript-tsconfig-json-example-1
 

Go to eclipse and refresh the directories and check for the js file creation

typescript-tsconfig-json-example-2
 

Check the output of js file in html page through browser

typescript-tsconfig-json-example-3
 

All Chapters
Author