typescript

Variables #

let apples = 5;
let speed: string = 'fast';
let hasName: boolean = true;
let nothingMuch: null = null;
let nothing: undefined = undefined;

Built in objects #

let now: Date = new Date();

Arrays #

let colors: string[] = ['red', 'green', 'blue'];
let myNumbers: number[] = [1, 2, 3];
let truths: boolean[] = [true, true, false];

Classes #

class Car {}
let car: Car = new Car();

Object literals #

let point: { x: number; y: number } = {
  x: 10,
  y: 20,
};

Functions #

const logNumber: (i: number) => void = (i: number) => {
  console.log(i);
};

//or

const logNumber =  (i: number): void  => {
  console.log(i);
};

 
0
Kudos
 
0
Kudos

Now read this

Fakes, spies, stubs & mocks

I learned how to test code using Jest. Today I’m working on a codebase that doesn’t have Jest and I have to use Jasmine and Sinon instead. The most confusing bit is going through the documentation and trying to understand what fakes,... Continue →