Update content/blog/22-typescript-flavors.md
All checks were successful
/ build (push) Successful in 38s

This commit is contained in:
Nycki 2025-02-05 06:39:29 +00:00
parent 8866deb454
commit a544a82fdb

View file

@ -41,7 +41,7 @@ this won't work correctly! It'll do something like this:
> on the 11th day of christmas...
> on the 111th day of christmas...
that's because I've mistakenly defined `n` as `'1'`, in quotes, which means it's actually a string, and not a number. when you do math on things that aren't strings, _sometimes_ it works how you expect, but not _always_. it would be nice if I had a way to scan my source code and say "whoops, did I ever treat the same thing as a string and a number without meaning to do that?" enter TypeScript:
that's because I've mistakenly defined `n` as `'1'`, in quotes, which means it's actually a string, and not a number. when you do math on things that aren't numbers, _sometimes_ it works how you expect, but not _always_. it would be nice if I had a way to scan my source code and say "whoops, did I ever treat the same thing as a string and a number without meaning to do that?" enter TypeScript:
```ts
let n = '1';
@ -54,7 +54,7 @@ TypeScript sees that I messed up, and it says "hey, that's not something you wou
you can also tell typescript intentionally 'hey, I am expecting this to be a type' and it'll throw the error even earlier:
```ts
let n: number = 1;
let n: number = '1';
// Type 'string' is not assignable to type 'number'.
```