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"]);