Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A possibly more elegant TypeScript solution:

  type NonEmpty<T> = [T, ...T[]];
  
  function head<T>(input: NonEmpty<T>): T {
    return input[0];
  }
https://www.typescriptlang.org/play/?ssl=5&ssc=2&pln=1&pc=1#...


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: