تخطَّ إلى المحتوى

Typescript.Ar

دليل TypeScript المختصر

نظرة عامة

TypeScript هي مجموعة فوقية مُميَّزة بالأنواع من JavaScript والتي تُترجم إلى JavaScript عادي. توفر ترقيم الأنواع الثابتة الاختياري، والفئات، والواجهات. تم تصميم TypeScript لتطوير التطبيقات الكبيرة وإعادة تجميلها إلى JavaScript.

الميزات الرئيسية

  • الترقيم الثابت للأنواع: اكتشف الأخطاء في وقت الترجمة بدلاً من وقت التشغيل.
  • الواجهات: حدد عقود لكود البرنامج.
  • الفئات: استخدم ميزات البرمجة الموجهة للكائنات مثل الفئات والوراثة وعوامل الوصول.
  • العموميات: أنشئ مكونات قابلة لإعادة الاستخدام يمكنها العمل مع مجموعة متنوعة من الأنواع.

البدء

تثبيت TypeScript:

Would you like me to continue with the remaining placeholders once you provide the complete text?```bash npm install -g typescript


**Compile a TypeScript file**:
```bash
tsc my-file.ts

Basic Types

  • boolean: true or false.
  • number: All numbers are floating point types.
  • string: Textual data.
  • array: An array of values of a specific type.
  • tuple: An array with a fixed number of elements of different types.
  • enum: A way of giving more friendly names to sets of numeric values.
  • any: A dynamic type that can be anything.
  • void: The absence of any type at all.
  • null`` and undefined**: Subtypes of all other types.
  • never: Represents the type of values that never occur.

Interfaces

interface Person {
  firstName: string;
  lastName: string;
}

function greeter(person: Person) {
  return "Hello, " + person.firstName + " " + person.lastName;
}

let user = { firstName: "Jane", lastName: "User" };

document.body.textContent = greeter(user);

Classes

class Greeter {
  greeting: string;
  constructor(message: string) {
    this.greeting = message;
  }
  greet() {
    return "Hello, " + this.greeting;
  }
}

let greeter = new Greeter("world");

Generics

function identity<T>(arg: T): T {
  return arg;
}

let output = identity<string>("myString");

Additional Resources