Write a generic getOr(obj, key, fallback) that returns obj[key] when it is not undefined, otherwise the fallback. The key must be a real key of obj, and the fallback must match that property's type.
Signature: getOr<T, K extends keyof T>(obj: T, key: K, fallback: NonNullable<T[K]>) => NonNullable<T[K]>
Practice keyof indexing plus NonNullable<T[K]> so the fallback and return type line up with the looked-up property.
Constrain K extends keyof T so only real keys are accepted.
The value type is T[K]; strip null/undefined with NonNullable<T[K]>.
Return the fallback when obj[key] is undefined.
Test natijalarini ko'rish uchun kodingizni ishga tushiring.