Back to Top
The nuts and bolts for
Creative web development

Getting Started with TypeScript

“Learn some of the basics of the TypeScript”

In late 2012, Microsoft introduced TypeScript, a typed superset for JavaScript that compiles into plain JavaScript. TypeScript focuses on providing useful tools for large scale applications by implementing features, such as classes, type annotations, inheritance, modules and much more! In this tutorial, Sayanee Basu will get started with TypeScript, using simple bite-sized code examples, compiling them into JavaScript, and viewing the instant results in a browser.

 

Type Annotations
Type annotations are an optional feature, which allows you to check and express your intent in the programs you write. Let's create a simple area() function in a new TypeScript file, called type.ts. Next, change the script source in index.html to type.js and run the TypeScript compiler with tsc type.ts. Refresh the page in the browser. The type annotations are expressed as part of the function parameters, they indicate what types of values you can pass to the function. For example, the shape parameter is designated as a string value, and width and height are numeric values. Type annotations, and other TypeScript features, are enforced only at compile-time. If you pass any other types of values to these parameters, the compiler will give you a compile-time error. This behavior is extremely helpful while building large-scale applications.

Read the full article

Share this Article