Shift + Enter · ప్రారంభించండి / పునఃప్రారంభించండి
కోడ్ ప్రాంప్ట్ గైడ్ని చదవండి
- ప్రోగ్రామింగ్ లాంగ్వేజ్
- TypeScript
- కష్టం
- మధ్యస్థం
Return the first element while preserving its type.
function firstItem<T>(items: T[]): T | undefined {
return items[0];
}
const firstNumber = firstItem([4, 8, 15]);
const firstName = firstItem(["Ada", "Lin"]);