ENع
الدرس 06 · Core type system

Unions and narrowing

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

A union type such as string | number says a value can be one of several types. Follow a seven-line function as tsc refuses a method that only strings have, then watch a typeof check split the union in two: string inside the if, number after it. Finally run the program, see "ab" and 7 take the same two paths and print AB 7.0, and learn why the check survives when the types are erased.

10 دقيقة8 خطوات5 أسئلةIntermediate
شكل 6 · تفاعلي
جارٍ تحميل الرسم…
أو ← →

اختبار يتاح بعد الخطوة الأخيرة.