Comment Comment by andrewghull Here's the final example in TypeScript if you find that easier to read: type NonEmpty<T> = [T, ...T[]] const head = <T>(list: NonEmpty<T>) => list[0] function getConfigurationDirectories(): NonEmpty<string> { const configDirsString = process.env["CONFIG_DIRS"] const [firstDir, ...restDirs] = configDirsString.split(',') if (firstDir === undefined) throw Error("CONFIG_DIRS cannot be empty"); return [firstDir, ...restDirs]; } function main() { const configDirs = getConfigurationDirectories(); initializeCache(head(configDirs)) } parent andrewghull 2 years ago