How To Type Faster
Hello, I hope you are doing great in this new position you are in. I am also writing this for myself as well as to help out the next generation of web developers who may be just starting out learning about HTML and CSS. As a developer, you need to know how to type your code faster.
Before we get into typescript let me preface myself by saying that it's not for beginners. It wasn't easy at first if you were new to typescript but there is no reason why you shouldn't give it try. There are plenty of tutorials online explaining everything you need and I have included the link below to a few of my favorites. So go on and read them and enjoy!
So, what is typescript?
Typescript is an open-source programming language and environment used to create highly performant JavaScript code and web applications from scratch. The goal of its development is to eliminate all unnecessary boilerplate, reduce errors, and make JavaScript readable so anyone can understand what's going on inside the code. For example, if given four or more variables, you create a function with these variables in it and then repeat yourself, your function will take up to 70% more time! (Typescript is based on Javascript which makes it extremely forgiving)
To learn Typescript, you don't write Javascript anymore. You write classes, functions, and properties which are methods of JavaScript. You can then use all those methods to add to a document with JSX which is a syntax extension for JavaScript.
If you are looking to write fast and readable code, typescript is better than javascript because it allows you to use every method written by jsx and works without giving out any parameters. That means you can reuse a basic HTML document with a class and add a new button function to it without having to worry about where the methods are attached to. Here is a simple example of the same file you write in Typescript with jsx.
// jsx
export const name = 'Harrison';
const score = '40';
const age = 23;
const height = 11;
function showScores(){
scored = '';
}
export function Harrison(name, score, age, height) {
return {
name,
score,
age,
height
};
}
Let's talk about one common typing pattern. When you write javascript/typescript, it's like you are coding every single line at once, but typescript has a lot of patterns that make things easier to understand (more patterns coming soon) so let's break that down. The var keyword is very useful when creating variables that are stored somewhere else and are accessible everywhere else within the function. A variable can also be declared as an object but the most commonly used is as an array or object which is what you see above. One way to access a variable and its contents are to use the bracket notation: // var hello){
echo "hello, world!";
}
The brackets are only there for variables (in this case hello only exists as an array) which is why they can also be accessed by using the console.log method or by adding curly braces like so: //hello{
console.log(hello);
}
When declaring a variable to avoid confusion and to make sure the type of variable matches the type of data the variable is holding, it's best to declare one variable with as another with a double parentheses which looks similar to the following code.
//declare variable = array([1, 2]);
var array = [1, 2]; //assigning variable to array
array = array[0]; //assigning variable to array with double parentheses
array = array[1]; //assigning variable to array with triple parentheses
array = array[1, 0, 1]; //assigning variable to array with triple parentheses
array = array[1, 1, 0, 1];
You would always remember to include double-brackets and triple-brackets wherever possible because they are sometimes confused and taken out of context. They should both represent the same thing so it's important to do that.
You will also notice that there are several ways to denote a variable, one of which is undefined (you can declare it this way or you can declare it as just an initial value). Some of the ways used are with the colon Operator (a.k.a the “C” word), with double square braces (which look like little squares), and with a mix of the two like so: //var name = undefined;
var name = undefined;
The colon Operator is sometimes called the semicolon. While you might think of the colon Operator as a form of parentheses, it uses a syntax similar to double parentheses. When you write this code you are creating two different variables with both double and triple-branched parentheses and that can cause some confusion. The colon operator is sometimes called by a different name. A colon Operator could be used with double parentheses which look like this or single parentheses and that is what you will use while writing code in Typescript.
// var foo = null,
foo = null; //declare a variable
var num = 3; //declare a variable with double parentheses
var num = 3, 5, 6, 7, 8, 9, 10
//declare a variable with triple parentheses
var num = 3
+ 5 + 6...
//declare a variable with triple parentheses
var num = 3, 5, 6, 7, 8, 9, 10, 11, 12
//declare a variable with a mix of the two brackets
var num = 3 + 5 + 6... + 7 //declare a variable with a double parentheses
var num = 3 + 5
+ 6
//declare a variable with a triple parentheses
var num = 3 +5 +6
+ 7
//declare a variable that has multiple double parentheses
var num = 3 + 3
+3 + 3
//declare a variable with multiple triple parentheses
var num = 3 + 3
+3,5,3
//declare a variable that has multiple double parentheses
var num = 3 +3
+3,5
//declare a variable that has multiple triple parentheses
var num = 3
+3
//create a new variable using double parentheses
var sum = 10; //create a new variable using with double parentheses //create a new variable using a mix of the two parentheses //create a new variable using a triple parentheses //create a new variable using double parentheses
var number = 0; //create a new variable using a mix of the two parentheses //create a variable using a mix of the two parentheses
var name = 'Harrison'; //create a variables with mixed double and triple parentheses //create a variable
name = 'Harrison'
//create a new variable with a double parentheses name = 'Harrison'
//create a new variable with a triple parentheses //create a new variable with a mix of the two parentheses
name = 'Harrison'
+
//create a variable with triple parentheses //create a new variable with a mix of the two parentheses
name = 'Harrison'
+ +
//create a variable with mixed double and triple parentheses //create a variable with a mix of the two parentheses
name = 'Harrison'
+ +
//create a variable with mixed double and triple parentheses //create a variable with a mix of the two parentheses
name = 'Harrison'
+ + +
//create a variable with mixed double and triple parentheses //create a variable with a mix of the two parentheses
name = 'Harrison'
+ +
//create a variable with mixed double and triple parentheses //create a variable that has a mix of the two parentheses name = 'Harrison'
//create a variable with a mix of the two parentheses
name = 'Harrison'
+ +
//create a variable with mixed double and triple parentheses //create a variable with a mix of the two parentheses
name = "Harrison"
+ +
//create a variable with mixed double and triple parentheses //create a variable with a mix of the two parentheses
name = "Harrison"; //create a Variable with mixed double and triple parentheses //create a variable with a mix of the two parentheses
name = "Harrison"
+ +
//create a variable with a mix of the two parentheses name = "Harrison"
//create a Variable with Mixed Double & Triple Paragraphs
name = "Harrison"
+ +
//create a Variable with Mixed Double & Triple Paragraphs
name = "Harrison"
+ +
//create a Value Object with Single Branch Assignment
title = 'Harrison'
+ +
//create a Property Object with Single Branch Assignment title = 'Harrison'
title = property 'title'
+ +
//create a Property Object with Single Branch Assignment title = 'Harrison'
title = property 'title'
+ +
//create a new Property Object with Single Branch Assignment title = 'Harrison')
title = property 'title'
+ +
//create a Sub-Object with Single Branch Assignment
title = 'Harrison'
+ +
//create a Property Object with Single Branch Assignment
title = property 'title'
+ +
//create a Sub Variable with Single Branch Assignment
title = property 'title'
+ +
//create a Sub-Object with Single Branch Assignment
title = 'Harrison'
+ +
//create a Sub Variable with Single Branch Assignment
title =
0 Comments