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

Generics

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

A generic function has a type parameter, T: a placeholder for a type, filled in fresh by every call. Watch tsc work out T = number from first([10, 20]) and T = string from first(["a", "b"]), give n and s their exact types, and use that to catch s.toFixed(1) before it can crash. Then the types are erased and the program prints A.

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

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