0%
تثبيت TypeScript وإعداده

التثبيت

قم بإعداد بيئة TypeScript الخاصة بك

10-15 دقيقة

تثبيت TypeScript وإعداده

في هذا الدرس، سنتعرّف على كيفية تثبيت TypeScript وإعداده لبدء التطوير بكفاءة.

المتطلبات الأساسية

قبل أن تبدأ، تأكد من توفر ما يلي:

  • تثبيت Node.js (الإصدار 14 أو أحدث)
  • npm أو yarn كمدير للحزم
  • محرر أكواد (يُنصح باستخدام VS Code)

التحقق من Node.js

node --version
npm --version

تثبيت TypeScript

1. التثبيت العام (موصى به للمبتدئين)

# Avec npm
npm install -g typescript

# Avec yarn
yarn global add typescript

2. التحقق من التثبيت

tsc --version

يجب أن ترى شيئًا مشابهًا لما يلي: Version 5.3.3

إنشاء أول مشروع TypeScript

1. إنشاء مجلد جديد

mkdir mon-projet-typescript
cd mon-projet-typescript

2. تهيئة المشروع

# Initialiser npm
npm init -y

# Installer TypeScript localement (recommandé pour les projets)
npm install -D typescript

# Installer les types Node.js (si nécessaire)
npm install -D @types/node

3. إنشاء ملف الإعداد

# Générer tsconfig.json
npx tsc --init

الإعداد باستخدام tsconfig.json

يتحكم الملف tsconfig.json في سلوك مترجم TypeScript:

{
  "compilerOptions": {
    // Version JavaScript cible
    "target": "ES2020",
    
    // Système de modules
    "module": "commonjs",
    
    // Dossier de sortie
    "outDir": "./dist",
    
    // Dossier source
    "rootDir": "./src",
    
    // Vérifications strictes
    "strict": true,
    
    // Résolution des modules
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    
    // Génération de source maps
    "sourceMap": true,
    
    // Déclarations de types
    "declaration": true,
    "declarationMap": true
  },
  
  // Fichiers à inclure
  "include": [
    "src/**/*"
  ],
  
  // Fichiers à exclure
  "exclude": [
    "node_modules",
    "dist"
  ]
}

التعليقات

التعليقات مدعومة عبر GitHub Discussions

سجّل الدخول باستخدام GitHub للمشاركة في النقاش

تم نسخ الرابط!