DEV Community

Discussion on: Some lesser known TypeScript notation

Collapse
 
click2install profile image
click2install

The non-null assertion operator is almost always a bad idea, it doesn't hold under refactor. In your example it would be better to combine nullish coalescing with the optional chaining so you provide a default value ... throw expressions will be a good fit here once included in the spec too. In general, optional chaining is best used with nullish coalescing for code safety, especially under refactor. Nice article to bring awareness though 👍.

Collapse
 
bionicjulia profile image
Bionic Julia

Thanks so much for the feedback! :) I'll look into this further.