Command Palette

Search for a command to run...

Login
TypeScript এ Interface এর সব ভ্যালু টাইপ বের করা
zisanurhaqueag
Zisanur Haque
·1 min read

TypeScript এ Interface এর সব ভ্যালু টাইপ বের করা

ধরা যাক আমাদের কাছে একটি UserProfile নামের Interface আছে, এখন আমরা চাই Interface এর সব প্রপার্টির টাইপ একত্রিত করে একটি ইউনিয়ন টাইপ বানাতে।

TypeScript এ এটা খুব সহজ এভাবে,

type UserProfileValue = UserProfile[keyof UserProfile];

তাহলে UserProfileValue এর মধ্যে থাকবে:

number | string | boolean | string[] | { 
  lastLogin: Date; signupSource: string 
} | (() => string)

এখানে যা হলো, keyof UserProfile দিয়ে আমরা Interface এর সব কী পাই। তারপর UserProfile[keyof UserProfile] দিয়ে আমরা ওই কী-গুলোর ভ্যালুর টাইপগুলোর সবকিছুর ইউনিয়ন পাই।

এভাবে আপনি খুব সহজে Interface এর সব ভ্যালু টাইপ একত্র করতে পারেন।

Comments

  • Type and hit enter to post comment
  • For multiline comments, use Shift + Enter
  • You can use markdown syntax for formatting

Cookie Consent

We use cookies to enhance your browsing experience and analyze our traffic. By clicking "Accept", you consent to our use of cookies.