Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
2
votes
0answers
9 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
14 views

rxjs returning diffrent observables depending on ansver [closed]

I need to make a check of the data in one observable and then subscribe to other observabels so far i got this, and it works with one observable but I need to return several ...
2
votes
0answers
16 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
14 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
0answers
22 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
37 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: ...
0
votes
1answer
32 views

Is there an elegant way to re write my angular code?

Hi Currently i have an angular 5 project . i have a method named createForm. it will basically create just a form. however the form created changes depends on the flight inventory code . if flight ...
2
votes
0answers
20 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
42 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
32 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
49 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
15 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
38 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 ...
12
votes
2answers
232 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 ...
0
votes
0answers
31 views

Axios Resource Level Rate Limiter with Priority

I'm using multiple APIs with different rate limits and also do requests to non-rate-limited websites and I didn't want to handle multiple axios instances for each type. There are quite a few limiters ...
2
votes
0answers
56 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
397 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
21 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 ...
0
votes
0answers
21 views

Complexity of a service method to fetch search results from an API

I tried the plug in CodeMetrics for Visual Studio Code along with some of my current Angular projects, and I was a little suprised about the outcome. I have a ...
2
votes
1answer
41 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
65 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
35 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
29 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
20 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
29 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
25 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
40 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
20 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
63 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
51 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
49 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
47 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
272 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
247 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
19 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
38 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
10 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
79 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
77 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: ...
1
vote
0answers
19 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
61 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
371 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
431 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
67 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". ...
0
votes
0answers
20 views

Angular service that configures translations based on current business case

I have a simple Angular Service that pre-configures translations for the ngx-translate library based on the currently logged in business case. I'm not sure if my switch case statement within the if/...
1
vote
0answers
21 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
52 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. ...
4
votes
1answer
51 views

Searching a nested data structure for 2 attributes

So I have the following data structures ...