How to convert a string to number in TypeScript?

Exactly like in JavaScript, you can use the parseInt or parseFloat functions, or simply use the unary + operator: All of the mentioned techniques will have correct typing and will correctly parse simple decimal integer strings like “123”, but will behave differently for various other, possibly expected, cases (like “123.45”) and corner cases (like null).  Table taken from this answer

How can I define an array of objects?

You are better off using a native array instead of an object literal with number-like properties, so that numbering (as well as numerous other array functions) are taken care of off-the-shelf. What you are looking for here is an inline interface definition for your array that defines every element in that array, whether initially present or introduced later: If … Read more

TypeScript foreach return [duplicate]

The cleaner way would be to not use .forEach. It’s almost never needed if you’re using TypeScript or a modern version of JavaScript: If the code inside your loop doesn’t have any side-effects and you’re just checking for a condition on each item, you could also use a functional approach with .some:

What is the Record type in typescript?

Can someone give a simple definition of what Record is? A Record<K, T> is an object type whose property keys are K and whose property values are T. That is, keyof Record<K, T> is equivalent to K, and Record<K, T>[K] is (basically) equivalent to T. Is Record<K,T> merely a way of saying “all properties on … Read more

Can’t bind to ‘formGroup’ since it isn’t a known property of ‘form’

RC6/RC7/Final release FIX To fix this error, you just need to import ReactiveFormsModule from @angular/forms in your module. Here’s the example of a basic module with ReactiveFormsModule import: To explain further, formGroup is a selector for directive named FormGroupDirective that is a part of ReactiveFormsModule, hence the need to import it. It is used to … Read more