TypeScript
TS
A language that adds static typing to JavaScript. Developed by Microsoft. Essential for large projects.
TS
A language that adds static typing to JavaScript. Developed by Microsoft. Essential for large projects.
TypeScript is a programming language that adds a static type system to JavaScript. It includes all the features of JavaScript while providing powerful type features such as type annotations, interfaces, and generics. Code written in TypeScript is compiled to JavaScript and runs in all browsers and Node.js environments.
TypeScript, developed by Microsoft in 2012 and released as open source, was designed under the leadership of Anders Hejlsberg (creator of C# and Delphi). As of 2025, it is the second fastest-growing language on GitHub, and major frameworks such as Angular, Vue 3, Deno, and Next.js have adopted TypeScript as their default or recommended language.
The core features of TypeScript are compile-time type checking, defining object structures through interfaces, and writing reusable components through generics. In addition, advanced type features such as union types, type guards, conditional types, and mapped types make it possible to express complex type relationships.
In practice, the biggest advantage of TypeScript is IDE support. In VS Code, you get autocompletion, real-time error detection, safe refactoring, and type-based documentation. This greatly increases productivity in large-team collaboration, and by catching runtime errors in advance at compile time, it dramatically reduces bugs.
// 1. 기본 타입 정의
let userName: string = "홍길동";
let userAge: number = 28;
let isActive: boolean = true;
let skills: string[] = ["TypeScript", "React", "Node.js"];
// 타입 추론 - 명시적 타입 없이도 타입 안전성 보장
let score = 100; // number로 추론
// score = "high"; // 오류! number 타입에 string 할당 불가
// 2. 인터페이스 - 객체 구조 정의
interface User {
id: number;
name: string;
email: string;
role: "admin" | "user" | "guest"; // 유니온 타입
createdAt?: Date; // 선택적 속성
}
function createUser(user: User): User {
return {
...user,
createdAt: new Date()
};
}
const newUser = createUser({
id: 1,
name: "김개발",
email: "dev@example.com",
role: "user"
});
// 3. 제네릭 - 재사용 가능한 컴포넌트
interface ApiResponse<T> {
data: T;
status: number;
message: string;
}
async function fetchData<T>(url: string): Promise<ApiResponse<T>> {
const response = await fetch(url);
const data = await response.json();
return {
data: data as T,
status: response.status,
message: response.ok ? "성공" : "실패"
};
}
// 사용 예시 - 타입 안전한 API 호출
interface Product {
id: number;
name: string;
price: number;
}
const products = await fetchData<Product[]>("/api/products");
// products.data는 Product[] 타입으로 자동 완성 지원
// 4. 타입 가드와 유니온 타입
type Result = { success: true; data: User } | { success: false; error: string };
function handleResult(result: Result) {
if (result.success) {
console.log(`환영합니다, ${result.data.name}님!`);
} else {
console.error(`오류: ${result.error}`);
}
}
"We're planning to migrate our existing JavaScript project to TypeScript. Converting everything at once is risky, so it would be better to set allowJs: true in tsconfig and gradually convert to .ts files. Let's start with the shared utilities and API type definitions."
"The biggest advantage of TypeScript is that it catches bugs at compile time. For example, if you define API response types as interfaces, you get autocompletion and type checking in the IDE, which can reduce runtime errors by more than 80%. Also, when refactoring, the type system tells you the full scope of impact, so you can safely make large-scale code changes."
"There's an as any cast on this API response type. If the type doesn't match at runtime, an error occurs, which defeats the purpose of using TypeScript. Add runtime validation with zod or io-ts, or share the OpenAPI spec with the backend and generate the types automatically. Also, is there a reason you used type instead of this interface? If extension is needed, interface is more suitable."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Using any neutralizes the type safety of TypeScript. When you don't know the type, use unknown and narrow it down with type guards. Enabling ESLint's @typescript-eslint/no-explicit-any rule can prevent the use of any.
Set "strict": true in tsconfig.json. Strict type checking such as strictNullChecks and noImplicitAny is enabled, allowing you to write safer code. For a new project, it is best to start with strict mode from the beginning.
When migrating an existing JavaScript project, do not convert all files at once. Use the allowJs and checkJs options to keep using .js files alongside, and convert to .ts sequentially, starting with the most important modules.