Basics of TypeScript
Ganesh Raja
Posted on June 11, 2020
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,
};
💖 💪 🙅 🚩
Ganesh Raja
Posted on June 11, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.