Type-safe JavaScript | Bug တွေ code ရေးတုန်း ဖမ်းနိုင်, IDE support အကောင်းဆုံး
string, number, boolean, any, unknown, union
interface, type alias, optional fields, readonly
Typed params/return, overloads, arrow functions
class, access modifiers, abstract, implements
Generic functions, classes, constraints, utility types
defineProps, ref<T>, composables, Vite + TS setup
Class, method, property decorators — @Log, @Memoize, @Singleton, DI container
Conditional types, mapped types, template literals, discriminated unions, infer
npm install -g typescript → tsc --init → tsc file.ts
// Basic types
let name: string = "Ko Ko";
let age: number = 25;
let active: boolean = true;
let items: string[] = ["a","b","c"];
// Union & Optional
let id: string | number = "abc";
let email?: string; // optional
// Interface
interface User {
id: number;
name: string;
email?: string; // optional field
readonly createdAt: Date; // can't change
}
// Function
function greet(name: string): string {
return `Hello, ${name}!`;
}
// Generic
function first<T>(arr: T[]): T {
return arr[0];
}
const num = first([1, 2, 3]); // T = number
const str = first(["a","b"]); // T = string