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