Skip to main content

Command Palette

Search for a command to run...

Introduction to Typescript

A quick overview of what Typescript is, features of this powerful language, and how to get started with it.

Published
2 min read

What is Typescript

TypeScript is a strongly-typed superset of JavaScript. TypeScript adds static types to JavaScript. TypeScript uses JavaScript and C# syntaxes and complies with native JavaScript. Today, TypeScript is being used to build large open-source projects.

TypeScript cannot run directly in the browser, instead the TypeScript code we write gets compiled into Javascript code, which can run directly in the browser. Any valid .js file can be renamed to .ts and compiled with other TypeScript files.

I will say, think of typescript as your friend who sits beside you to check your code.

Here are the key features of TypeScript.

  • TypeScript is simple, easy to learn.

  • It can run on any environment Javascript runs on. It doesn’t need a VM(Virtual Machine) or specific runtime environment.

  • TypeScript extends JavaScript syntax, so any existing JavaScript programs work with TypeScript without any changes.

  • supported by most of the popular developer IDEs including Visual Studio, Visual Studio Code, Sublime Text, Atom, Eclipse, Emacs, etc.

  • TypeScript supports OOP features like classes, inheritance, interfaces, generics etc.

  • TypeScript tooling provides auto-completion, type checking and source code documentation.

How to install Typescript

Via npm (Node.js Package Manager) command-line tool

npm install -g typescript

How to check if typescript is Installed

tsc -v

Congratulations! You can start writing typescript.

D

I personally prefer to avoid the term "strong" when talking about types.

When people say JavaScript is weakly typed, they're usually talking about 1 of 2 aspects:

1 - types are determined at runtime based on results of expressions, as opposed to explicit declaration ahead of time; in that case, "weak" is a misnomer because really they're talking about duck typing or the dynamic typing. If something is dynamically typed, a compilation process can't determine the type of a variable, so it must be determined during program execution. Static typing works the opposite way. Regardless of when typing is determined, there are still types.

2 - they're talking about the extensive type coercion features javascript has. Can be annoying to grapple with these for newcomers, hence why they're referred to as "weak typing" by devs who may be coming from say Java. But like in number 1, there are still types.

I'd say since TypeScript is a superset of JavaScript that adds optional static typing features, it may be enough to say just that because TypeScript does technically preserve all vanilla JS features.

That was long... sorry lol. But I guess I'm just a nerd and I really like talking about programming language syntax and semantics 🤓.

Cheers 🍻

1
S

You're right dave. Going by your second point, as a JavaScript dev, we pride ourselves in being able to do anything in JavaScript rather than having to use another language that's traditionally used for the job (and it's also something a lot of devs hate about the JavaScript community), i.e. Node for back end, React Native for mobile development etc. Devs from strongly typed language are big critique of JavaScript, even now that TypeScript is a thing. Like you said, TypeScript is a superset, so all valid (dynamicly typed) JavaScript is valid TypeScript which makes it something of an intermediate cross of the two rather than a true strongly-typed implementation of JavaScript.

For the newbie, we just have to use it (strong-typed) in better context. That doesn't nullify the fact that all dynamicly typed are valid in ts.

1
Introduction to Typescript