DEV Community

Cover image for Basics of TypeScript
Ganesh Raja
Ganesh Raja

Posted on • Updated on

Basics of TypeScript

So, Today I get started with the basics of TypeScript.

I was always aginst typescript because it increases the size of the codebase. Whenever you write more code the chance for the error is high. But recently I faced some difficulties maintaining the type of the object and making sure it doesn't contain any invalid values while developing.

So I decided to give it a shot and started with basics today. Very soon will build a node and react project with typescript.

You can find my Repo Link here
https://github.com/ganeshraja10/Latest-Tech-Learnings

const a: number = 22;

interface Point {
  x: number;
  y: number;
  z?: number;
  w?: any;
}

const point2D: Point = {
  x: 22,
  y: 22,
};

const point3D: Point = {
  x: 22,
  y: 22,
  z: 33,
};

type AddValueType = (x: number, y: number) => number;

const addValue: AddValueType = (x: number, y: number) => x + y;

let multiple: number | string = 22;

multiple = 'string';

interface PointX {
  x: number;
}

interface PointY {
  y: number;
}

type Point2Dim = (PointX & PointY) | string;

const Point2D2: Point2Dim = {
  x: 22,
  y: 33,
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)