typescript_intro.md

Roger Siver
2 min readJul 5, 2021

Typescript is JavaScript with more rules, and a lot of fancy features. Like if JavaScript wasn’t just ran in runtime environment but a development environment as well. At this point in “Operation Spark” the coding Bootcamp that I’m in, we’re getting pretty familiar with vanilla JavaScript. we’ve managed a filesystem with bare node, and instantiated objects every possible way up to ES6 class creation. It’s hard to imagine yet another way to create things in your JavaScript environment but here we are. I set out to answer a handful of questions for my class.

What is TypeScript?

Well according to them

“TypeScript offers all of JavaScript’s features, and an additional layer on top of these: TypeScript’s type system.”

In JavaScript you can reassign a variable to whatever datatype you would like. In JavaScript you have to run your code to see how the JavaScript interpreter is going to compile it, and you won’t see datatype/variable assignment type errors until runtime. Typescript solves this problem by compiling your code in the editor, and showing any run time errors related to syntax or datatype right in your editor. In typescript when you declare a variable it has a set datatype that cannot be changed

Everybody has seen

const message = “hello”message();

TypeError: Message is not a function

You have to write all your code and run it to get this far. that sucks. In a typescript file with the same code in it, in your editor of choice, you will get a line annotation

This expression is not callable. Type ‘String’ has no call signatures.

Useful, helpful, verbose.

These examples are from Typescript Docs: The Basics, by the way.

const user = {  
name: "Daniel",
age: 26,};
user.location; // returns undefined

Were gonna see that user location doesn't exist without a terminal, no chrome console is needed to see that we need to change user.location or our code isn't gonna work. Have you seen the handy refactoring features inside vscode? We can extract a function out of its scope or easily convert asynchronous functions. Typescript is handling this in the background! VScode is written in typescript and ran in an electron environment. Good stuff, I’m excited for the day when I can ditch JavaScript for typescript for large projects with variables and datatypes flying around. We can write JavaScript and run it way more confidently, at a larger scale. Typescript Typescript Typescript

--

--