Skip to content

arifuddincoder/phl2-assignment-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript Blog

1. What is the use of the keyof keyword in TypeScript? Provide an example.

keyof হলো TypeScript-এর একটি type operator
এটি কোনো object type এর সব keys বের করে তাদেরকে একটা union type বানায়।

📘 Example

type Person = {
  name: string;
  age: number;
  city: string;
};

// keyof Person মানে:
type PersonKeys = keyof Person; 
// => "name" | "age" | "city"

1. Explain the difference between any, unknown, and never types in TypeScript.

  • any → যেকোনো কিছু হতে পারে, টাইপ-চেক নেই।
let x: any = 10;
x = "hello"; // allowed
  • unknown → নিরাপদ any, ব্যবহার করার আগে টাইপ-চেক দরকার।
let y: unknown = "world";
if (typeof y === "string") {
  console.log(y.toUpperCase());
}
  • never → এমন কিছু যা কখনো ঘটবে না।
function fail(msg: string): never {
  throw new Error(msg);
}

About

Solutions for Programming Hero Level 2 - Assignment 1 (TypeScript problems and concepts).

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors