Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
0
votes
0answers
46 views

pick interesting properties from a js object

Utility functions, similar to Lodash.pick but it also picks beyond level 1 and inside arrays. Useful for offline storage of big objects we want to skim. An interactive version of this code, with an ...
5
votes
0answers
196 views

Reference enum values in Angular template without aliasing the enum type

Is there a way to improve this code? I'd like to use the enum type PaymentMethoddirectly in the angular template without renaming it to ...
1
vote
0answers
26 views

Using Nominal Typing in Typescript [closed]

I have a variable, which represents a date, but I have the need of keeping it in string format. I want to be sure that this string is in a specific format, in this specific case ...
2
votes
1answer
2k views

Angular Rest API generic service and implementation service

I'm wondering if there's a better way to write the ApiService and the CategoryService so that CategoryService is basically just a call to extend ApiService with the string 'category' and the base type ...
1
vote
1answer
75 views

Flattening the nested Objects

The original idea behind the problem is that the API I'm working with returns one type of a response for GET, and requires another type to do ...
3
votes
1answer
39 views

Managing Angular subscriptions

There are different methods to get data from server in Angular application: Get Observable from the service and subscribe to it at component Create Subject at the service and subscribe to the Subject ...
2
votes
0answers
18 views

Submiting form and transform model to match backend

I have different model in frontend and backend. When I submit form in frontend I need to transform that object to match backend model. Is there a better way than this one: ...
2
votes
0answers
69 views

RxJs observables pipes SwitchMap and async with typealong search input

I'm using RxJs for type along search, I setup an observable to emit a value after 1 second so it behaves like http with delay. I subscribe to it via the async operator in the template, the component ...
1
vote
1answer
694 views

React continuous polling

I have a Notifications component in my React app, which continuously polls the server for new notifications. The app uses Redux for storing notifications. When a new notification is received, it is ...
4
votes
1answer
90 views

Maze algorithm to find path between points

I am creating an algorithm to find the shortest path between two points in a maze but my current solution is too slow. This is what I did: Helper classes: ...
1
vote
1answer
55 views

Creating a form based on flight intentory

I have an Angular 5 project with a method named createForm. It will basically create just a form. However, the form created changes depends on the flight inventory ...
2
votes
0answers
22 views

Recuperate user's details into fake JSON server

This is the 'details.ts' which define the user's details that I want to recuperate in a JSON (user's role, logintime, duration). ...
2
votes
0answers
47 views

Calculate reservation cancellation penalty based on date difference

The website I'm developing allows customers to book an appointment. They can also cancel their appointment with the following rules: if the appointment is cancelled between 48 hours and 1 hour in ...
-1
votes
2answers
35 views

Function which updates an array and returns a map

export const updateWatchlist = (coin: IAsset, watchlist: IAsset[]) => { watchlist.push(coin) return watchlist.map((c) => c) } Is this 1-line-able with a ...
5
votes
1answer
71 views

Zork look-a-like written in TypeScript

I've been working on a a text based game with a very simple battling system. There are way to many questions I can ask to get reviewed about this project, but I'll take small steps at a time (this is ...
2
votes
0answers
22 views

Error handling in express without middlewares and using class structure

This is a simple implementation of Django's sample project "Poll" using and express. The controller code: ...
1
vote
0answers
58 views

React.js hook to validate a form on submission

I am fooling around with hooks in React and I'm stumbling against decisions that I need to make regarding implementation. Below is the code for the custom useForm hook which can be used to hook up ...
14
votes
2answers
286 views

Emulation of SE's text input control for tags

Introduction I used React to write a component, which is meant to be a faithful emulation of the input for "Tags" which you see at the top of every question/topic on SE. Why this project? If you're ...
2
votes
0answers
397 views

Angular 8: Scroll spy implementation for a timeline Contents

I have made a timeline component that can have multiple milestone/major/minor as sub components nested within timeline container component. I have also added a side navigation for that lists all ...
2
votes
1answer
9k views

TypeScript implicit 'any' type with computed property key

(irrelevant code removed for demo purposes) I am new to using TypeScript and I have this React component which has an object literal inside the component, which I'm then accessing using a computed ...
3
votes
0answers
89 views

Copy-to-clipboard function from a React.js component

I have a React component with a copyToClipboard method, which all works fine, but feels extremely verbose and quite hacky (namely, having to create a new select ...
2
votes
1answer
55 views

Throttling promise execution (API requests, etc)

I was working on a client for a remote api and realized that I needed to throttle requests at a maximum rate of 4 Hertz (4 requests per second). I wrote a simple typescript class to do it and wanted ...
1
vote
1answer
483 views

FormArray total of each formgroup via RxJS

Stackblitz - https://stackblitz.com/edit/angular-plp4rb-formarray-total-prs9ay I'm new to RxJS observables. I've created a form array where the total for a line is ...
5
votes
1answer
51 views

Typescript monad for data being loaded

I have been struggling to make typescript happy about the types. I am pulling data from our backend API and I wanted to give context to the data. Basically it is a monad with 4 shapes: Initial (...
2
votes
0answers
33 views

The modularization of the Express entry point

I've been working on a project to make myself more comfortable with NodeJS, especially Express and TypeScript. Searching and reviewing a lot of approaches of the people, providing bootstraps for it, I ...
1
vote
0answers
21 views

Dynamically build tagged union and helper that allows its instantiation and calling of its static methods

I am working on a typescript react/redux app that provides a visual interface for the code editor with a predefined set of instructions. It's basically a tree structure of objects that I call ...
4
votes
0answers
34 views

Product allocation on trucks

The premise of this program is to use the least amount of vehicles to allocate the available load. What I did is allocate the largest amount of load on the truck that fits better. This program's ...
1
vote
0answers
124 views

Extract useMemo to its own custom hook

I wanted to know if the useMemo function extracted like this is valid at all. This is a whole component (Sorry for the imports) that uses useMemo to get a data that is grabbed from the server using ...
3
votes
0answers
77 views

Implementing custom observable classes

I want to implement my own custom observable class so I can have a hierarchy of components and the closest defined configuration item bubbles to the front. ...
1
vote
0answers
27 views

Dragging and dropping a spot using TypeScript

Currently my code is based around mouse events so that it is easier to test but I will be swapping these to touch events once I have had the code reviewed. The idea of the UX is that you need to ...
3
votes
1answer
77 views

Separating items into ordered and unordered lists

I'm trying to group all the types which have ordered-list-item & unordered-list-item into new object. How can I simplify the function and reduce multiple return statements? ...
3
votes
0answers
56 views

Communication with interactive program using ChildProcess

There is an interactive program, namely Microchip Debugger (Later called MDB), which I want to communicate with from NodeJS program. You can think about it as any console-based debugger - they all do ...
1
vote
0answers
136 views

vuejs vuex element-ui used to toggle a login dialog but req

I have a login dialog working in vue js with typescript. I want to trigger the open via a button on page, but also by toggling a value in the vuex store. It is working by 2 watchers: Watching the ...
2
votes
1answer
49 views

Primitive full-text search on some properties of an object

I am not a JS/TS Guru, so i wanted to ask if one could write this better. I needed a very primitive Full-Text-Search of some properties of an Object. What do you think? ...
2
votes
0answers
762 views

Accordion component with Angular 7

I have to made an accordion-, respectively "zippy"-component using Angular 7. I'm new to Angular. Just started with it a few weeks ago. But with some Google-usage I was able to implement the ...
2
votes
0answers
669 views

Mapping nested arrays from API response

I have some selects on my html page that I want to populate with the response from my backend API. The response looks like this JSON response ...
1
vote
0answers
34 views

angular service for centralizing common grid functions

I have an angular 7 app that is data focused and as a result has dozens of grids. These grids are from the Kendo UI for ANgular component library made by Telerik. These grid components expose hooks ...
1
vote
1answer
149 views

Unit Test case to check if localstorage is empty once I logout of the Web app

I am trying to clear my localstorage when I am logging out of the application. I want to write a unit test case in Jasmine to check if this task is performed when logout function is run. I am writing ...
1
vote
0answers
11 views

RXJS and Ionic- Sequencial Subscriptions Waiting on User Action

In an Ionic App a user can open a new browser via "inAppBrowser". I'm trying to get the stats of the user before they go into to the inAppBrowser, get the stats again when browser closes, and then run ...
2
votes
1answer
1k views

Retry a Promise resolution N times, with a delay between the attempts

I want some JavaScript code to take 3 things as parameters: A function returning a Promise. The maximum number of attempts. The delay between each attempt. What I ended up doing is using a ...
2
votes
0answers
150 views

Angular polling and plotting component using Firebase

I could use some help refactoring my component and service. I have a lot of nested logic and wasn't sure what I could do to improve this. I'm new to Angular 7 and their piping syntax. I suspect this ...
1
vote
0answers
19 views

Versatile React component that maps style attributes

I'm creating a versatile component with styled-components that essentially just maps style attributes. I feel my type declarations seem inefficient in getting access to props. Is it appropriate to ...
0
votes
1answer
36 views

Checking if a multi dimensional array's given property is empty or not for the whole collection

This is what I am doing and it's working: ...
2
votes
0answers
34 views

Two Angular animations for modal dialogs

I'm using Ionic 4 and Angular animations to animate modals. I created the following two functions that control the animations but they share a lot of repeated code. Is there a way I can clean these up ...
0
votes
1answer
95 views

Angular pipe to suppress sensitive information

I have created an Angular pipe to suppress the sensitive information like credit cards, bank account, ABA numbers etc. This is working fine but I would like to know if this is the best possible way ...
1
vote
0answers
1k views

Stateless tooltip component using React hooks and ref

What I'm trying to create is a generic tooltip component that I can use anywhere. I decided on a stateless component and the use of hooks and ref. Explanation 💡 Hook, because I wanted to have a ...
2
votes
1answer
2k views

A countdown clock in TypeScript

The gist of the code is, you give it a date, it will start counting down how many days, hours, minutes and seconds left by emitting an event 'countDown' and once 0 is reached 'expired' event is ...
0
votes
1answer
116 views

JavaScript - Difference between two dates in days or less [closed]

I have 2 dates that I would like to have the difference between them in days and if less than a one day simply show "less than a day". ...
1
vote
0answers
44 views

Optimistic validation on tab change

I have a rather large UI for editing a user within a Angular application. It is split in multiple tabs and in order to reduce complexity the user cannot change the tab unless there is no validation ...
1
vote
0answers
217 views

Angular Websocket service with wait for response sending

I am writing an Angular Websocket service that can send messages to a server and then can subscribe to the response. I am grateful for every suggestion to improve this. ...

1 2
3
4 5
8