I have a data model that I can’t change in this project. I’m trying to strip down and simplify the sample code below, so hopefully this still makes sense with what I’m trying to re-produce. Let’s say I have two stores. One store holds “containers” and the other store holds “items” – each store is independently used throughout the app
Tag: typescript
Angular Form Array – Dynamically Add Value to Nested Form Group
I followed the this video to create a reactive form to input data into an Angular application I am working on. It does what I want for the most part, however, I have added an additional control(“setNumber”) to be added in the reactive form array, but instead of inputting a value through the input fields of “name” and “gender”, to
Is it possible to make a localStorage wrapper with TypeScript typed parameters and mapped return values?
I’m trying to construct a TS wrapper for localStorage with a TS schema that defines all the possible values in localStorage. Problem is that I can’t figure out how to type the return value so that it’s mapped to the approriate type from the schema: for example if I want to call LocalStorage.get(“some_number”), I want the return type to be
Lodash typescript – Combining multiple arrays into a single one and perform calculation on each
I have a Record<string, number[][]> and trying to perform calculation over these values. An example input: For each key, and for the specific year I want to do the following For this I have been playing around with lodash/fp. is there a way to somehow pass the inputs and iterate over them, and somehow get a callback function to get
How to resolve – Argument of type is not assignable to type – TYPESCRIPT
I have a function, that takes among other things an object of functions: The idea is that i can pass any object of functions that i want, but typescript for some reason requires that i pass all the properties that exist on type , otherwise it throws an error For instance if D is And i call the function as:
Using union type as function parameter
I have a type defined like so: where FieldValue is a union of types: I have a variable object where I then declare the functions set by the above types: This produces an error where the values in the object are not of type FieldToAction, I kind of understand why since I am now constraining the parameter to be a
Best practices for declaring or assigning types
I’m a beginner with TypeScript (Day 1), but have worked on above average JavaScript projects. I’m looking for advice about some “best practices” and standards when it comes to declaring or assigning types in code. At the moment, I find myself doing it for literally everything which is essentially making my code unreadable. For example, consider this: This is a
Typescript returning array of objects with unknown keys
I’m new to TypeScript, and trying to slowly migrate an existing JS (react) project to TypeScript. I have a function executing a query: And I’m calling this in numerous locations: The last line gives an error, because the field ‘cnt’ is unknown. How to best solve this? The return type is always Object[], but the content ob the object depends
Pushing array into an array of array in TS
I am coming from Python, and am not entirely familiar with the ‘proper’ JS/TS way of doing things. I am looping through the elements of a set, and I am pushing lists of some of the elements onto a 2D array. I am getting the following error TypeError: Cannot read properties of undefined (reading ‘push’). What am I doing wrong,
extend typescript array of object without modifying the source
I have this List object, but later on the shape changed, I need an extra id property, but how to not modify List? Answer You can extend the List interface