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

Swift and TypeScript use ! sort of like .unwrap(). Probably a better use of it than "never" tbh.


I'm not completely opposed but I'm also not sure syntax sugar for unwrap is a great idea.


If ! was just used as never it could still be used as an operator, because those are different contexts AFAICT. However, its use in macro invocations seems likely to be more difficult to differentiate from operators.


We actually use this version of never a lot in our code at $WORK

```

export function never(message?: string): never {

  throw new Error(message ?? 'Reached an impossible state');
}

const [foo = never()] = dbQueryThatReturnsOne();

```

I guess it's en par with .unwrap()




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

Search: