At Codesphere, we code mostly in Typescript, not necessarily because it is our favorite language, but because we found out that it made us the most productive.<p>However, recently I came across two very strange behaviors, (I know, they are common in the JavaScript Bubble) and I felt the urge to share them!<p>1: ['1', '2', '10'].map(parseInt);
I came across this when I wanted to format some user input, convert it into numbers and put them in a chart.<p>Alt Text<p>['1', '2', '10'].map(parseInt);<p>This does not work, because map passes three arguments into parseInt() on each iteration. The second argument index is passed into parseInt as a radix parameter. So each string in the array is parsed using a different radix. '2' is parsed as radix 1, which results in NaN, '10' is parsed as radix 2, which is 3, and '1' is parsed as the default radix 10 because its index 0 is falsy.<p>2: Inheritance of 'readonly' in Typescript
During a code review we came across the idea to make methods readonly. What happened next left us a little confused.<p>It's actually not possible to make a method readonly, but it is possible to make a readonly property with a function type, which has the same effect.<p>Interestingly enough, it is not possible to assign the property again for instances of the same class, but it is possible to inherit a class and override the property, as well as, assign the property on an instance of a subclass.<p>class Roman {
readonly jonas: () => void = () => console.log("huh?");
}<p>class Elias extends Roman {
jonas: () => void = () => console.log("oh no, override works!");
}<p>const elias = new Elias();
elias.jonas(); // oh no, override works!
elias.jonas = () => console.log("oh no, assignment works too!");
elias.jonas(); // oh no, assignment works too!<p>What is your experience with Typescript? What do you find most confusing in Typescript?