A collection of small things I've learned while working with JS/TS.
- Not throwing your own error when something has gone wrong won't actually result in less errors, it will just result in less readable errors
- You can store a number in a string but you can't store a string in a number
- The blob pattern for matching both '.ts' and '.tsx' files is
*.ts?(x) - The blob pattern for matching
.ts,.tsx,.jsand.jsxfiles is*.{ts?(x),js?(x)} - If you are ever working with unix timestamps and are using
dayjsbe VERY careful and look up the documentation for how unix timestamps are handled by it, it can be confusing Number.MIN_VALUEis not actually the lowest possible number in JS, its the closest number to 0 that isn't zero. If you actually want the minimum JS number you need to useNumber.MAX_VALUE * -1- Always be explicit with your boolean checks, even if the language considers
0as falsey, always dox === 0instead of!x, ALWAYS. If you only do it here and there, you'll probably forget to do it when its actually important.