<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: joyonto kumar roy</title>
    <description>The latest articles on DEV Community by joyonto kumar roy (@joyontokumar).</description>
    <link>https://dev.to/joyontokumar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F185580%2F384b2a65-f38e-487a-8536-2f70a95602be.jpeg</url>
      <title>DEV Community: joyonto kumar roy</title>
      <link>https://dev.to/joyontokumar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joyontokumar"/>
    <language>en</language>
    <item>
      <title>The number type in TypeScript.</title>
      <dc:creator>joyonto kumar roy</dc:creator>
      <pubDate>Sun, 29 Jun 2025 07:41:07 +0000</pubDate>
      <link>https://dev.to/joyontokumar/the-number-type-in-typescript-3kb9</link>
      <guid>https://dev.to/joyontokumar/the-number-type-in-typescript-3kb9</guid>
      <description>&lt;p&gt;In TypeScript, number is a primitive type that can hold all kinds of numbers including integers, floats, hexadecimal, binary, octal, and scientific notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let age: number = 25;
let price: number = 99.99;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Usage in TypeScript with type annotation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let score: number = 90;
let height: number = 5.9;
let hex: number = 0xff;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Useful Number Methods:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;toFixed()&lt;/strong&gt;&lt;br&gt;
Rounds the number to a fixed number of decimal places:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let pi = 3.14159;
console.log(pi.toFixed(2)); // "3.14"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;toExponential():&lt;/strong&gt;&lt;br&gt;
Converts to scientific notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let big = 123456;
console.log(big.toExponential()); // "1.23456e+5"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;toString(radix):&lt;/strong&gt;&lt;br&gt;
Converts number to string in specified base:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let num = 255;
console.log(num.toString(16)); // "ff"
console.log(num.toString(2));  // "11111111"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Type Guarding:&lt;/strong&gt;&lt;br&gt;
Ensure type safety when using number | string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function double(x: number | string) {
  if (typeof x === "number") {
    return x * 2;
  }
  return parseFloat(x) * 2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Special Numeric Values:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 1 / 0;          // Infinity
let b = -1 / 0;         // -Infinity
let c = parseInt("abc"); // NaN (Not a Number)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should always check for isNaN() when doing conversions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Math Library Functions:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Math.round(3.6);   // 4
Math.floor(3.9);   // 3
Math.ceil(3.1);    // 4
Math.abs(-10);     // 10
Math.pow(2, 3);    // 8
Math.sqrt(16);     // 4
Math.random();     // Random number between 0 and 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Enums with Numbers:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum Size {
  Small = 1,
  Medium = 2,
  Large = 3
}

let selected: Size = Size.Medium;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enums are great when you need readable numeric identifiers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom Type Guard:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isNumber(val: unknown): val is number {
  return typeof val === "number" &amp;amp;&amp;amp; !isNaN(val);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Number() constructor বা wrapper:&lt;/strong&gt;&lt;br&gt;
In JavaScript/TypeScript, the Number() function is used to convert other types (like strings or booleans) to a number. It can also be used as a wrapper object, though this is less common and generally discouraged.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let n = new Number(5);  // object wrapper (not primitive)
typeof n; // "object"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;isNaN() vs Number.isNaN()&lt;/strong&gt;&lt;br&gt;
New developers often don't know the difference between the global isNaN() function and Number.isNaN(). It would be good to mention this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;isNaN("abc"):; // true (coerces to NaN)
Number.isNaN("abc"); // false (doesn't coerce)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Number parsing functions:&lt;/strong&gt;&lt;br&gt;
Mentioning the Number() function alongside parseInt() and parseFloat() increases completeness.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Number("123.45"); // 123.45
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Type narrowing with isFinite():&lt;/strong&gt;&lt;br&gt;
When dealing with scientific or dynamic values, isFinite() becomes helpful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Number.isFinite(Infinity); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>typescript</category>
      <category>number</category>
      <category>types</category>
    </item>
    <item>
      <title>The string type in TypeScript.</title>
      <dc:creator>joyonto kumar roy</dc:creator>
      <pubDate>Sat, 28 Jun 2025 14:37:04 +0000</pubDate>
      <link>https://dev.to/joyontokumar/the-string-type-in-typescript-2916</link>
      <guid>https://dev.to/joyontokumar/the-string-type-in-typescript-2916</guid>
      <description>&lt;p&gt;The string type is a primitive type that holds a text value.&lt;br&gt;
In TypeScript, the string type is a type that can only hold text values (such as "Hello", 'World', or template strings).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let name: string = "Joyonto";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, the variable name can only accept string values.&lt;/p&gt;

&lt;p&gt;With the string type, you can use text formatting, string methods (like length, toUpperCase(), etc.), and template literals.&lt;/p&gt;

&lt;p&gt;Additionally, in TypeScript, you can define more specific and safer types using literal strings, union strings, and template literal types.&lt;/p&gt;

&lt;p&gt;The two main ways to use the string type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Declaring the type normally:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let city: string = "Dhaka";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Type inference (TypeScript automatically infers the type):&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;let country = "Bangladesh";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are different ways to write strings.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Double Quotes:&lt;br&gt;
&lt;code&gt;let name: string = "Joyonto";&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Single Quotes:&lt;br&gt;
&lt;code&gt;let message: string = 'Hello';&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Backticks (Template Literals — Very Important)&lt;br&gt;
`let name = "Joyonto";&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;let greeting = &lt;code&gt;Hello, ${name}!&lt;/code&gt;;`&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All JavaScript built-in string methods work with the string type in TypeScript:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let text: string = "Hello World";

text.length;            // 11
text.toUpperCase();     // "HELLO WORLD"
text.toLowerCase();     // "hello world"
text.includes("Hello"); // true
text.split(" ");        // ["Hello", "World"]
text.replace("World", "TypeScript"); // "Hello TypeScript"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;- Literal Types in String:&lt;/strong&gt;&lt;br&gt;
In TypeScript, you can use literal value types with strings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let status: "success" | "error" | "pending";

status = "success"; // valid
status = "loading"; // Error: "loading" is not assignable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- Union of String Types&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Role = "admin" | "user" | "guest";

let myRole: Role;

myRole = "admin";  // ✅
myRole = "manager"; // ❌
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- String Enums&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enum Direction {
  Up = "UP",
  Down = "DOWN",
  Left = "LEFT",
  Right = "RIGHT"
}

let dir: Direction = Direction.Left;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- String type parameter in a function&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name: string): string {
  return `Hello, ${name}!`;
}

greet("Joyonto"); // "Hello, Joyonto!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- Optional, Default, and Nullable String&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printMessage(msg?: string) {
  console.log(msg ?? "No message");
}

let username: string | null = null;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- Utility Types + String&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Person = { name: string; age: number };
type Keys = keyof Person; // "name" | "age"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;- String Literal Types with Functions (Narrowing)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type NotificationType = "success" | "error";

function showNotification(type: NotificationType) {
  if (type === "success") {
    console.log("🎉 Success!");
  } else {
    console.log("❌ Error!");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, TypeScript uses type narrowing to understand that if the type is "success", then the other branch must be "error".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- as const with string literals:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const role = "admin" as const;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates an immutable string literal type, where role cannot be any other string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Type Guards for String&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function logIfString(value: unknown) {
  if (typeof value === "string") {
    console.log(value.toUpperCase());
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the type is unknown, it is checked using typeof like this to handle the string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Utility Type — Record with string&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type LangText = Record&amp;lt;string, string&amp;gt;;

const texts: LangText = {
  title: "Hello",
  description: "Here is the description",
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Record, you can create any key-value pair type where both the key and value are strings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some real-life examples:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Gender = "male" | "female" | "other";
function handleGenderChange(g: Gender) {
  // do something
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Status = "success" | "error";

function showToast(status: Status) {
  if (status === "success") {
    alert("Submitted successfully!");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using TypeScript’s string type in a React.js project: Hello.tsx (a component that accepts string type props).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";

type HelloProps = {
  name: string; 
};

const Hello: React.FC&amp;lt;HelloProps&amp;gt; = ({ name }) =&amp;gt; {
  return &amp;lt;h1&amp;gt;Hello, {name}!&amp;lt;/h1&amp;gt;;
};

export default Hello;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;App.tsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import Hello from "./Hello";

const App: React.FC = () =&amp;gt; {
  const userName: string = "Joyonto";
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Hello name={userName} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>string</category>
      <category>types</category>
    </item>
    <item>
      <title>TypeScript Types — Everything at a Glance</title>
      <dc:creator>joyonto kumar roy</dc:creator>
      <pubDate>Sat, 28 Jun 2025 14:15:39 +0000</pubDate>
      <link>https://dev.to/joyontokumar/typescript-types-everything-at-a-glance-4n21</link>
      <guid>https://dev.to/joyontokumar/typescript-types-everything-at-a-glance-4n21</guid>
      <description>&lt;p&gt;TypeScript is a layer on top of JavaScript that brings type safety to our code. This helps catch errors early and makes the code easier to read and maintain.&lt;/p&gt;

&lt;p&gt;In today’s article, we’ll dive into all the important types in TypeScript. We’ll provide examples based on real-life scenarios so that both beginners and experienced developers can benefit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We will divide the types into three main categories:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Primitive Types&lt;/li&gt;
&lt;li&gt;Special Types&lt;/li&gt;
&lt;li&gt;Complex Types&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Primitive Types:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅ string holds text or string values.
let username: string = "Sadia";
Use cases: user name, messages, titles, etc.

✅ number holds whole numbers or decimal values.
let price: number = 299.99;
let age: number = 25;
Use cases: age, price, quantity, etc.

✅ boolean holds a true or false value.
let isLoggedIn: boolean = true;
Use cases: login status, condition checks, etc.

✅ bigint is used to store very large numbers.
let population: bigint = 9007199254740991n;
Use cases: large data like bank account numbers.

✅ symbol is always unique. Used as unique keys in objects.
let id: symbol = Symbol("id");
Use cases: unique properties or secret keys.

✅ undefined means a variable has been declared but not assigned any value.
let result: number | undefined;
Use cases: variable is declared but still holds no value.

✅ null is used to intentionally indicate "no value".
let selectedUser: string | null = null;
Use cases: when you want to explicitly say "no value".

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Special Types:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅ any can hold values of any type and turns off type checking.
let data: any = "Hello";
data = 123;
Use case: When the type is unknown, but should be used with caution.

✅ unknown can hold any type like any, but you must check the type before using it.
let input: unknown = "Text";
if (typeof input === "string") {
  console.log(input.toUpperCase());
}
Use case: A safer alternative to any when handling unknown data.

✅ void is used when a function doesn’t return anything.
function logMessage(message: string): void {
  console.log(message);
}
Use case: For functions that perform an action but don’t return a value.

✅ never is used when a function never returns (e.g., throws an error or has an infinite loop).
function throwError(): never {
  throw new Error("Something went wrong!");
}
Use case: For functions that never finish or always fail.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Complex Types:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅ array stores multiple values of the same type.
let numbers: number[] = [1, 2, 3];
let fruits: string[] = ["apple", "banana"];

✅ tuple stores a fixed number of values of different types.
let user: [string, number] = ["Alice", 30];
Use case: When you need to store mixed-type values in a fixed order.

✅ object stores data as key-value pairs.
let person: { name: string; age: number } = {
  name: "Tanvir",
  age: 27,
};

✅ function can have defined parameter and return types.
function add(a: number, b: number): number {
  return a + b;
}

✅ union allows a variable to be one of multiple types.
let value: string | number = "Hello";
value = 42;

✅ intersection combines multiple types into one, requiring all their properties.
type Admin = { role: string };
type User = { name: string };
type AdminUser = Admin &amp;amp; User;

const admin: AdminUser = {
  role: "superadmin",
  name: "Karim",
};

✅ literal allows a variable to have specific, fixed values.
let status: "success" | "error" = "success";

✅ enum creates a named set of constant values.
enum Direction {
  Up,
  Down,
  Left,
  Right,
}

let move: Direction = Direction.Up;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the next part, we will dive deep into all the important TypeScript types that will help you learn TypeScript more thoroughly. We will explore the usage of Primitive, Union, Intersection, Tuple, Enum, Interface, Generics, and Utility Types with real-world examples and detailed explanations.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is TypeScript? Explain with a simple real-life example.</title>
      <dc:creator>joyonto kumar roy</dc:creator>
      <pubDate>Sat, 28 Jun 2025 12:43:20 +0000</pubDate>
      <link>https://dev.to/joyontokumar/what-is-typescript-explain-with-a-simple-real-life-example-4pin</link>
      <guid>https://dev.to/joyontokumar/what-is-typescript-explain-with-a-simple-real-life-example-4pin</guid>
      <description>&lt;p&gt;When people hear “TypeScript,” many assume that you need to know programming to understand it.&lt;br&gt;
But that’s not true. Today, we’ll understand TypeScript in real-life terms — without writing any code.&lt;/p&gt;

&lt;p&gt;Whether you’re a complete beginner or even a programmer who struggles to understand TypeScript — this post is for you.&lt;/p&gt;

&lt;p&gt;TypeScript is a programming language built on top of JavaScript that helps prevent mistakes by warning you in advance.&lt;/p&gt;

&lt;p&gt;JavaScript quietly accepts whatever we write — whether it’s right or wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TypeScript says:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;“Hold on — there’s a mistake here. Fix it first, then I’ll run it.”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It’s a language that catches your mistakes while you’re writing code.&lt;br&gt;
As a result, the software becomes much more reliable and secure.&lt;/p&gt;

&lt;p&gt;🎯 Real-Life Example 1: Online Form&lt;/p&gt;

&lt;p&gt;Imagine you’re entering your date of birth in a field on a government website.&lt;/p&gt;

&lt;p&gt;✅ Scenario 1: Like TypeScript&lt;/p&gt;

&lt;p&gt;If you accidentally type “Rahim” in the date of birth field, the form immediately says —&lt;/p&gt;

&lt;p&gt;❌ "Please enter a valid date"&lt;br&gt;
👉 TypeScript works exactly like this — it immediately stops you when you give the wrong input.&lt;br&gt;
❌ Scenario 2: Like JavaScript&lt;/p&gt;

&lt;p&gt;You type whatever you want in the date of birth field — “abc”, “Rahim”, “123” — and the form accepts it.&lt;br&gt;
But later, the wrong date gets saved on the server, which causes issues in the system.&lt;/p&gt;

&lt;p&gt;👉 JavaScript works like this — it doesn’t say anything even if you enter wrong input.&lt;/p&gt;

&lt;p&gt;🏪 Real-Life Example 2: Shopkeeper vs. Customer&lt;br&gt;
Imagine you work in a shop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With JavaScript:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A customer comes to buy something. You give them the product without asking.&lt;br&gt;
Later you realize — they didn’t pay!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With TypeScript:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the customer hasn’t paid, you don’t give the product under any circumstances.&lt;br&gt;
You make sure the payment is complete before handing over the product.&lt;/p&gt;

&lt;p&gt;👉 TypeScript checks first: Is everything okay?&lt;br&gt;
🛠️ When / Why to Use TypeScript&lt;/p&gt;

&lt;p&gt;✅ When working on large projects:&lt;/p&gt;

&lt;p&gt;When an app has many features, many pages, and many developers — maintaining code with JavaScript becomes difficult.&lt;br&gt;
TypeScript warns you in advance about where mistakes are happening.&lt;/p&gt;

&lt;p&gt;🔍 Example: E-commerce sites (Daraz, Amazon), banking apps, large SaaS products&lt;/p&gt;

&lt;p&gt;✅ When working in a team:&lt;/p&gt;

&lt;p&gt;If you work alone, it’s easier to spot mistakes. But in a team, everyone works on different files — making it harder to find errors.&lt;br&gt;
TypeScript clearly shows who expects what type of data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔗 Benefits:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The input/output types of functions are clear New developers can easily understand the code&lt;/p&gt;

&lt;p&gt;✅ When using API data&lt;/p&gt;

&lt;p&gt;When you receive data from a REST API or GraphQL API, TypeScript can check whether the data format is correct.&lt;/p&gt;

&lt;p&gt;📦 Example:&lt;br&gt;
If the API says there is user.name, but you mistakenly write user.fullName — TypeScript will immediately warn you.&lt;/p&gt;

&lt;p&gt;✅ When using a library or framework (React, Angular, etc.)&lt;/p&gt;

&lt;p&gt;Frameworks like React, Angular, Next.js work very well with TypeScript.&lt;br&gt;
Using TypeScript allows better control over the props and types of components.&lt;/p&gt;

&lt;p&gt;✅ When creating reusable functions/components&lt;/p&gt;

&lt;p&gt;If you write functions that will be used in many places, defining types with TypeScript reduces the chances of mistakes.&lt;/p&gt;

&lt;p&gt;🔁 Reusability increases&lt;br&gt;
🔍 Bugs decrease&lt;/p&gt;

&lt;p&gt;✅ If you want future-proof code&lt;/p&gt;

&lt;p&gt;When you write code with TypeScript, it becomes easy for others—or even yourself—to understand it in the future.&lt;br&gt;
This makes refactoring, debugging, and documentation much easier.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>ts</category>
    </item>
    <item>
      <title>Complete TypeScript Setup Guideline</title>
      <dc:creator>joyonto kumar roy</dc:creator>
      <pubDate>Fri, 27 Jun 2025 14:22:30 +0000</pubDate>
      <link>https://dev.to/joyontokumar/complete-guide-to-setting-up-and-running-typescript-37a7</link>
      <guid>https://dev.to/joyontokumar/complete-guide-to-setting-up-and-running-typescript-37a7</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. Install Node.js and npm&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To run TypeScript, you must have Node.js and its package manager npm installed. Download: Go to &lt;a href="https://nodejs.org" rel="noopener noreferrer"&gt;https://nodejs.org&lt;/a&gt; and download the LTS version.Verify Installation:&lt;/p&gt;

&lt;p&gt;Open your terminal and run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node -v&lt;br&gt;
npm -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see the version numbers of Node.js and npm if everything is installed correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Create a New Project Folder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a folder where you'll set up your TypeScript project:&lt;br&gt;
&lt;code&gt;mkdir my-ts-project&lt;br&gt;
cd my-ts-project&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Initialize Your Project with npm&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the following command to generate a package.json file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init -y&lt;/code&gt;&lt;br&gt;
The -y flag automatically accepts all default values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Install TypeScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install TypeScript as a development dependency:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install typescript --save-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Create TypeScript Configuration File&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Generate the tsconfig.json file, which stores the configuration settings for the TypeScript compiler:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx tsc --init&lt;/code&gt;&lt;br&gt;
This will create a default config file. You can later customize it based on your project's needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Create Your First TypeScript File&lt;/strong&gt;&lt;br&gt;
Create a folder named src and add a file named index.ts inside it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir src&lt;br&gt;
touch src/index.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, add the following code inside src/index.ts:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function greet(name: string): string {&lt;br&gt;
  return&lt;/code&gt;Hello, ${name}!&lt;code&gt;;&lt;br&gt;
}&lt;br&gt;
console.log(greet("Joyonto"));&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Compile TypeScript into JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To compile your TypeScript code, run:&lt;br&gt;
&lt;code&gt;npx tsc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will compile your .ts file into a .js file. By default, it will create the compiled file in the same folder unless you specify an outDir in tsconfig.json.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;code&gt;src/index.ts → src/index.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Run the Compiled JavaScript File&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now run your JavaScript file with Node.js:&lt;br&gt;
&lt;code&gt;node src/index.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see the output:&lt;br&gt;
Hello, Joyonto!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. (Optional) Add Scripts to package.json&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To simplify your workflow, you can add scripts to your package.json like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"scripts": {&lt;br&gt;
  "build": "tsc",&lt;br&gt;
  "start": "node src/index.js"&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you can run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run build   # Compiles the TypeScript code&lt;br&gt;
npm start       # Runs the compiled JavaScript&lt;/code&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>setup</category>
      <category>guideline</category>
    </item>
  </channel>
</rss>
