Andrew Hansen
  • Home
  • About
Subscribe

typescript

A collection of 2 posts
What is the ! (exclamation mark / bang) operator when accessing a value in TypeScript?
typescript

What is the ! (exclamation mark / bang) operator when accessing a value in TypeScript?

Sometimes in a TypeScript codebase you might see code like this: const bar = myObject!.foo!.bar // or const obj = myObject! The exclamation/bang operator that comes after accessing a property (also called a "postfix bang") is known as a non-null assertion. The use case for this operator is to convert
Apr 15, 2022 — 5 min read
How to convert a string to 
a number in TypeScript
typescript

How to convert a string to a number in TypeScript

You're writing a TypeScript application and you hit an error like this: Argument of type 'string' is not assignable to parameter of type 'number'.(2345) This could happen for a number of reasons. For example, I often run into this when reading a value from an input field. I intend
Jan 17, 2022 — 3 min read
Andrew Hansen © 2022
Powered by Ghost