Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
-2
votes
2answers
105 views

So many if and else conditions [closed]

I have this class ...
0
votes
0answers
19 views

Trying to secure a payment transaction with mysqljs2

In my web app, I am trying to secure a payment transaction, that is: prevent users spending more than they have, especially in the case of concurrent execution and prevent partial execution. ...
0
votes
1answer
71 views

Having trouble with this Koan - solved it, but I don't think what I wrote is correct in regards to Typing

I'm working through these Koans: https://github.com/paytonrules/typescript.koans#readme I'm on file 3, collections, the very first function foreach: ...
3
votes
1answer
85 views

A React - Typescript custom hook for any request (GET, POST, PUT, DELETE) to my back end

I'm building a full stack exercise app and some of my objects include routines, exercises, exercise sets etc. Instead of writing out specific get, post, put and delete requests for each resource, I ...
5
votes
4answers
4k views

Cracking the Coding Interview: "Problem 1.5. One Away"

I am going one-by-one through problems in the "Cracking the Coding Interview". This question is about problem 1.5. One Away. Since I was never good in "algorithming", any suggestions are highly ...
0
votes
0answers
47 views
2
votes
2answers
68 views

Calling functions if certain strings are in an array

I have these few helper function that are used to check if the string in the given array is present and if the certain steps are present and then only have the other function fire. The reason I ...
2
votes
1answer
78 views

Typescript type checking of hierarchical types

I want to create a hierarchy of Typescript interfaces because I think classes would be an overkill in my case. The main obstacle is checking if an object has a specific type. I solved it this way: <...
1
vote
0answers
50 views

Genetic Algorithm Typescript

I learnt a little about genetic algorithm. And I made a program from typescript that tries to evolve and match word/sentence using genetic algorithm. But if I give a little longer sentence it takes ...
4
votes
1answer
141 views

Wrap async method in a way that the method is invoked only once for all calls that occur while the first of them is not resolved

Imagine we have a function that returns a Promise, ie call a GET endpoint of an api and return the response data. ...
0
votes
1answer
38 views

Typescript angular queryparams

I have some code like this ...
0
votes
0answers
36 views

Normalizing URL pathnames in TypeScript

I’m writing backend code for a website, and I’ve been surprised by the fact that a URL’s path component isn’t normalized at all, retaining trailing and duplicate slashes (...
1
vote
1answer
62 views

Checking if two shapes collide in TypeScript (double dispatch)

Basically, I'm trying to create a generic way to check if two shapes are colliding. I think this is kind of a "double-dispatch" problem, but I'm unsure if there is a better way to solve it ...
2
votes
1answer
82 views

TypeScript, React and Node app to get 'games' data from a database and display them on a frontend

This is only one of the first apps I've built with Node, React and TypeScript. I was wondering what could be made better. This is at this point the best I've been able to come up with, but I'm not ...
0
votes
0answers
27 views

Calculate minimum buy/sell amount that exchange will allow the order to be placed based on current price

I have created calculateMinimumAmount to calculate the minimum buy/sell amount that exchange will allow the spot order to be placed based on the current price. The ...
8
votes
2answers
188 views

JSON4 parser in Typescript

Context I may have accidentally gotten a little sidetracked during homeschooling, and wrote a JSON4 parser in Typescript during the down-time. This project started as an idea that I got while ...
1
vote
1answer
38 views

How to keep current HtmlElement active and change its properties?

I have a simple class that listens click and draws two points on the page. If first point is not exist it is drawn. When second point is present it should be changed after each click. I dislike this ...
0
votes
0answers
54 views

Commands loader

Loader - load commands files(classes) from directory of commands and module, if the commands are very simple and similar, then I put them in 1 file with the name of the module and load them through ...
4
votes
2answers
67 views

Are there technical issues/disavdantages on this BaseService that aims to simplify calling API endpoints

I have created an angular BaseService that aims to simplify calling API endpoints I would like to know if you see any code smells, bad patterns or architecture issues. What disadvantages could this ...
0
votes
0answers
54 views

Best practice to denote circular references in typescript classes and objects

Setup I am writing a class based, object oriented algorithm in typescript. In many cases, a class will create another child class, passing itself as an argument to the child class. For example: <...
2
votes
2answers
154 views

Generic Object mapping function

I implemented as an exercise a function which maps over object values in Typescript, and I am truly horrified by my type annotations. The function: ...
1
vote
1answer
36 views

Managing duplicate class instances in a javascript Set

I have a class called Thing. For simplicity, let's say it initializes with a unique id, and that's all that's unique about it: ...
0
votes
2answers
73 views

Simplifying the array of objects with comma separated values

Looking a way to reduce the below code to get comma separated values from the list of arrays By using ECMA or plain old vanilla JS. How should we achieve this? Actual Array Data: ...
1
vote
1answer
62 views

How can I refactor for handling multiple proto generated service clients by eliminating double await and the DRY code?

I'm having doubts about which is the best strategy to manage the many service clients in this web app. "Best" in terms of a good compromise between user's device RAM and Javascript execution ...
0
votes
1answer
56 views

RxJs - Flat nested swithMaps and pass variables on Http interceptor

How can the following method be flattened? I tried to pipe all the operators to the first pipe (from(this.fireAuth.currentUser)) but I lost access to the previous ...
0
votes
1answer
121 views

toggle boolean with if statement

I currently I have this code if (this.showAllOnlineFriends === false) { this.showAllOnlineFriends = true; } else { this.showAllOnlineFriends = false; } When ...
0
votes
1answer
96 views

This code renders a time dilation calculator

I've been learning React for about a month now. I wrote a small interactive calculator to show the effects of time dilation under special relativity. It's Node/React/Razzle(for SSR)/Typescript/...
0
votes
1answer
385 views

Unit test using mocks

As some part of my application needs connection to database I wanted to create tests that use mocks to avoid running special instance of database just for testing. That gave me a glimpse of how can I ...
0
votes
2answers
49 views

Verify application configuration from JSON file with matching type using TypeScript in an Angular project

To bootstrap our application we have a configuration stored in a JSON file. This config holds different settings, like definition of endpoints (e. g. an API or SMS gateway etc.) or some default values ...
0
votes
0answers
129 views

TypeORM EventSubscriber unit testing

I've been playing with TypeORM and I wanted to create proper tests for my EventSubscriber. I also wanted those test to be independent from database connection. I believe I managed to achieve my goal. ...
0
votes
0answers
16 views

Handling the first value for a variable, with Redux and the Backend service. Angular, Redux

I'm feeling this code is messy and also repeats between all components that needs to handle backend data. Any comment is appreciated. ...
2
votes
0answers
32 views

I’d like some feedback on my theme system implementation in TypeScript for my website

I’m currently building myself a website using GitHub pages. I wanted to have a theme system, and recently rebuilt my implementation. It now manages a <style> ...
3
votes
0answers
153 views

Space shooter game in TypeScript

I recently started learning TypeScript and created a small space shooter. I would like to get some feedback on the structure of my code. I have some classes with both static and instance methods with ...
0
votes
1answer
48 views

Unit Test case for services method in angular

I want to write the test case for Service class. My Service Class dynamic-form.service.ts ...
2
votes
1answer
56 views

Rxjs search in Angular

I created an rxjs search for a hiring company, but I got rejected for the following reason: -performance issue on a bigger data set. -bugs My question is how can I make this code better for the next ...
0
votes
0answers
29 views

Passing data between middleware in Express.js

I wrote a middleware for user authentication and I wanted to pass some data between authentication and request handler. What I thought would be a nice solution is to add that data into request body ...
2
votes
0answers
48 views

How to reduce the Cognitive Complexity of this code based on Thomas J. McCabe’s Cyclomatic Complexity

I know there are if, then, else and switch. But the code below is a mixture of if, then else, else if, else. ...
0
votes
0answers
199 views

Mongoose virtual field declaration in Typescript interfaces

I'm recently started learning Node.js and I'm trying to write a simple Todo app using Mongoose. Since I'm also try to learn Typescript I wanted to combine my basic knowledge on both topics and I ...
2
votes
1answer
32 views

Typescript : Adding types to a function that takes in a string and returns a different promise based on the string

I have a function that takes in a string and based on the string hits different APIs to fetch images. I have solved it by writing an interface and then as the return type of the function, it returns a ...
0
votes
0answers
16 views

Show contents in a book chapter and sections in a highly normalized repository

I want to present books that has chapters and sections, and contents in each book, chapter and section. This is my schema: ...
1
vote
0answers
36 views

How to abstract DOM manipulation in a simple intuitive way

I am building a library to abstract DOM manipulation. Here's what the usage looks like: ...
0
votes
0answers
29 views

JS, a multi purpose function

this is an Angular application, this page will have a list and sublist with action for each one (add/edit/delete) the buttons (add/edit) will show a popup with the same form except the landmark will ...
0
votes
0answers
31 views

Is there a better way for this ui component?

I need to create a component for displaying a list of avatar users....If the users present in the array is more then 3 I have to display a number to indicate the remaining amount of users. Example: <...
0
votes
0answers
2k views

Understanding import/no-cycle problem in eslint

I have a some code in which eslint thrown an error of the type: import/no-cycle, but I don't understand where this cyclic dependency comes from. The exact error ...
0
votes
0answers
10 views

Simplifiy the following flow for upload file status tracking

I am using angular and rxjs, and I am doing the following : I would like to upload an image to GCP, so I need to generate a signed url, upload the image,and while showing status of all the request. ...
0
votes
0answers
26 views

How do I avoid doing a search to compute a "normalized color"?

Before I go on with how I tried to do this, some background. WCAG provides a method that computes luminance as part of the contrast ratio computation. What I am trying to do is given a color in RGB ...
0
votes
0answers
13 views

Animating Pathfinding Generically

This is part of a project I built to visualise pathfinding algorithms. These files run the algorithms and gather a list of frames, which are used to show the animations. algorithms.ts ...

1
2
3 4 5
10