Thuta Learning
TypeScript
AdvancedProgrammingintermediate

Union Types & Aliases

• Union Types: Variable တစ်ခုက type တစ်ခုထက်ပို၍ ဖြစ်နိုင်သောအခါ pipe (|) character ဖြင့် သတ်မှတ်နိုင်သည်။

• Type Aliases: type keyword ဖြင့် custom type name အသစ်တစ်ခု ဖန်တီးနိုင်သည်။

typescript
// Type Alias for a complex type
type StringOrNumber = string | number;

function printId(id: StringOrNumber) {
  console.log("Your ID is: " + id);
}

printId(101);
printId("abc-101");
You should see
Your ID is: 101 Your ID is: abc-101
Union Types & Aliases | Thuta Learning