Trung BìnhTypeScript iconTypeScript

Path aliases trong TypeScript (paths config) là gì?

paths trong tsconfig.json map import paths để tránh relative paths dài.

Cần configure cả bundler vì TS compiler chỉ handle types, không transform imports.

json
// tsconfig.json
{ "compilerOptions": { "paths": { "@/*": ["./src/*"] } } }
typescript
// vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
  resolve: { alias: { '@': '/src' } }
});
// Dùng: import { Button } from '@/components/Button'

Xem toàn bộ TypeScript cùng filter theo level & chủ đề con.

Mở danh sách TypeScript