Why does this if statement not recognise numbers?

This code works fine on letters, returning if the letters are upper or lower case but it always returns the number as "6 is a uppercaseletter" let userLetter = prompt("Please enter an uppercase, lowercase letter or a number"); if (typeof userLetter === ‘number’) { userLetter = userNumber; alert(`${userNumber} is a number`); } else if (userLetter.toUpperCase()… Read More Why does this if statement not recognise numbers?

Type-inference for switch-case block with dynamic case strings

A tricky TS challenge. Say one has two objects with a type property, and a specific property, fooData or foo2Data, that is specific to the type value of the object. For example: const dynamicString: string = ‘abc’ const fooTypeName = `foo${dynamicString}` as const // const fooTypeName: `foo${string}` const foo2TypeName = `foo${dynamicString}2` as const // const… Read More Type-inference for switch-case block with dynamic case strings

How can I iterate through object of objects data to fill angular table

I’m having a hard time trying to iterate data fetched from api through angular bootstrap table. From a first approach I was mapping the data to prsnl variable declared as prsnl: any and initialized in the function bellow: getAllPersnlValues(data) { return this.persnlService.getPersnl(data) .pipe( map((response) => response) ).subscribe((res) => {this.prsnl = res; console.log(‘prsnl’, this.prsnl)}); } In… Read More How can I iterate through object of objects data to fill angular table

How to convert values from certain keys of an array to numbers?

I have the following array of objects const mi_array = [{ agrupacion: "Total país", col2015: ‘81.8’, col2016: ‘86.4’, col2017: ‘67.3’, col2018: ‘70.8’, col2019: ‘67.6’ },{ agrupacion: "otra cosa", col2015: ‘90.8’, col2016: ‘67.4’, col2017: ‘39.3’, col2018: ‘50.8’, col2019: ‘95.6’ }]; I need to transform this into something like this: const new_array = [{ name: "Total país",… Read More How to convert values from certain keys of an array to numbers?

Function argument type inference and conditional type

I’m trying to cover following case: I have a function which accepts a boolean and returns value of RealItem | ImaginaryItem type. I’m using conditional type to narrow the return type based on boolean argument. type RealItem = { color: string } type ImaginaryItem = { description: string } export function createItem<T extends boolean>(isReal: T):… Read More Function argument type inference and conditional type

Get the value of a parameter and make it the type of another parameter

The behavior I’m looking for can be implemented with overloading: function fun(elType: "input", params: Input): number; function fun(elType: "swtich", params: Switch): number; function fun(){ return 2 } Where if I run: fun("swtich", SOMETHING_OF_SHAPE_SWITCH) //compiles fun("input", SOMETHING_OF_SHAPE_INPUT) // error fun("input", SOMETHING_OF_SHAPE_INPUT) //compiles I was wondering if it can be done by checking the parameter directly: interface… Read More Get the value of a parameter and make it the type of another parameter