Getting started with TypeScript
The TypeScript language is an npm package that can be installed from the npm registry using the following command:
npm install -g typescript
In the preceding command, we chose to install TypeScript globally in our system so that we can use it from any path in our development environment. Let's see how we can use TypeScript using a simple example:
- Open VSCode and select File | New File… from the main menu options.
Enter
app.ts
in the New File… dialog and press Enter.- As we have already learned, TypeScript files have a
.ts
extension. - Use the dialog that opens to create the new file. VSCode will open the file inside the editor.
- Type the following snippet into the
app.ts
file:
const title = 'Hello TypeScript!';
- Although we have created a TypeScript file, the preceding snippet is valid JavaScript code. Recall that TypeScript is a superset of JavaScript that provides syntactic sugar through its...