DEV Community

Cover image for Basics of TypeScript
Ganesh Raja
Ganesh Raja

Posted on • Edited on

5

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

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs