Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

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

Display nested list within Angular app

I'm looking to optimise this code. Items ...
0
votes
1answer
32 views

Handling Circular References Without Recursion

Despite the many decent answers to this question, one was unable to find an iterative solution. Here's what I came up with: Code: ...
1
vote
0answers
30 views

Parse proxy strings to array of objects

The goal of this module is to take in a string (user input, someone copy and pasting a large list of proxies) and parse it into an array of objects. I appreciate any and all feedback, but I'm ...
0
votes
0answers
12 views

Snake in React TypeScript

This is a really simple standard snake game written in React. I've included my custom React components and hooks. Most of the game logic is hidden behind an API written in plain procedural TypeScript, ...
0
votes
2answers
38 views

Looping Array object with conditions and comparison the performance with ECMA VS Vanilla JS

The Plain vanilla JS needs to converted in to advanced ECMA. The below 3 snippets shown yields the correct result. Need to identify which among them is performance oriented ...
0
votes
0answers
27 views

Sorting Algorithm Visualiser in React with TypeScript

This code animates sorting algorithms in the browser. I've included all the React components I've used and left out the individual sorting algorithm implementations. SortingVisualiser.tsx ...
2
votes
0answers
29 views

How do I create an “Environment Variable Setter”?

I have a NodeJS/Typescript project. In server.js, I want to set my environment variables from a .env file. To achieve this, I am ...
1
vote
0answers
21 views

Passing value/data from a page to another page using Vue.js and Typescript

I have a markdown editor in View A which is showing the result in the current View. I'm trying to pass a result to another page which is View B. In the View A, a button exist to share the markdown ...
1
vote
1answer
26 views

Typescript typed Map [closed]

I have the following code: ...
3
votes
1answer
222 views

I need help optimizing a function that returns all divisors

This is my code: export function all_divisors(num: number): number[] { return range(1, num+1).filter(i => num % i === 0).toArray(); } the ...
0
votes
0answers
33 views

Best practice for multiple conditional HTML options with similar code blocks

So I'm pretty new to HTML/Angular and frontend tech in general. I'll include my code below, but as you'll see there's a LOT of commonality between the switch cases, what I'd like to try do is have ...
1
vote
1answer
42 views

How can I make this function that checks whether a number is a palindrome better?

I have this code: export function is_palindrome(num: number): boolean { return [...num.toString()].reverse().join("") === num.toString(); } which ...
1
vote
0answers
54 views

Game of Life in TypeScript React

This is my first React project. I've included the main files that don't just contain boilerplate. This is a visualization of Conway's Game of Life, with a few toggleable features like starting/...
0
votes
0answers
12 views

Find alignable blocks of digits between different bases

In cases where two radices are powers of a common sub-case (e.g., base 8 and base 16 are both powers of base 2), it is possible to align blocks of digits between representations to make converting ...
2
votes
1answer
29 views

MongoDB Filter between two dates

Simple code for getting documents that have a creationDate between two values in mongodb. If the user provides only one of the values the code should still work and ...
2
votes
1answer
42 views

Filtering Array Based on Element Values

Required to splice specific element value in an array based on the condition. Both the below code does the same job and yields the correct results. But couldn't figure out how to reduce coding ...
0
votes
0answers
28 views

Implementing Django's “reverse” functionality in Angular-Routing

I've started learning Angular (With Angular 10) roughly 2 months ago and I recently began wanting to avoid hard-coding my URLs under any circumstances, but was unable to find anything that satisfied ...
1
vote
0answers
54 views

Angular Typescript Async queue service

i've implemented a waiter service in Angular for syncronice multiple calls to one async function and i want to know if there exists a simplier way of atchiving the same result or if it's over ...
2
votes
2answers
36 views

Convert boolean array to integer in Typescript

I have a database object that has a field called workdays, it's a array boolean that contains 7 elements representing whether the user is active on the ...
4
votes
1answer
122 views

Performant Sort function for big arrays

In sort(arr), I want to sort an array. Children must be beneath their parent. And children of the same parent are sorted using ...
4
votes
1answer
45 views

Catching Errors in Factory Method with express.js

My express.js application uses a lot of promises for interacting with a variety of services. Instead of including try/catch with each one, I've setup a fail safe factory method for all my express ...
2
votes
0answers
38 views

Hashtable Visualizer in TypeScript

Implementation is based on the MVC design pattern, with callbacks to allow model and view to communicate with controller. Concerns: It's not ideal to have async code inside the model, i.e the model ...
1
vote
1answer
44 views

Small Counter by typescript with React

I am learning typescript with React and come up with this small program that each button count how many time by clicking and record which button got click. Please help me to take a look if all the ...
5
votes
1answer
45 views

getting inferences working with typescript pubsubber

So I'm learning typescript and I'm making a simple functional PubSub system. I want the user to be able to define topics and the data for those topics. So far I've got the below code, but I really ...
1
vote
1answer
66 views

How can i simplify the following If code?

I have the following code in JS (using last ES2020), the current code check if the type is 'asporto' or 'takeaway' and adding to ...
4
votes
3answers
90 views

Parsing “key: value” format in which values can span multiple lines

So I've written a function which parses a fairly simple key-value pair syntax. Each pair can span across multiple lines, as long as the value does not have a colon in it. If it does, then any new line ...
3
votes
2answers
148 views

Angular10 RxJS - Interceptor to add/refresh JWT Token

I have a project, for which I use Tokenauthentication with JWT Tokens. I am relatively new to Angular Development and rxjs in particular, so there are a lot of concepts I am likely not yet familiar ...
1
vote
0answers
16 views

Typescript: command pattern with orm

Hello I would like to know which pattern would be better in this case, I have many ifs and validations in my useCase, I was between strategy and commadn pattern to decouple this: ...
2
votes
1answer
44 views

typescript : clean code remove or decrease alot if's

Hello I have the following code, where I need to do many checks of calls from the database, My TypeEnum: ...
2
votes
1answer
55 views

Handle database validation (exists, unique constraint, etc) [closed]

Let's assume you are writing a REST Api with a common structure like Controller > Service > Repository > Database. In the database there's a table with a column with a unique constraint: <...
2
votes
2answers
65 views

Random game code id generator in typescript

Below is a simple typescript class used to generate a room code for an online lobby-based game (for example, https://jackbox.tv/ uses 4 digit codes to join rooms) The goal of the class is to quickly ...
3
votes
1answer
42 views

Conversion to typescript from javascript

This is my first attempt in converting a pure javascript to typescript. Any comment? ...
1
vote
1answer
26 views

TodoItem component type checking for optional prop

I have a TodoItem component that looks like this: ...
2
votes
0answers
24 views

Vue 3 composition API typescript using ref in Object

Hi I using Vue 3 with Typescript. In my code I have variable: ...
3
votes
1answer
51 views

Checking Object keys set with value against another Object keys

I'm willing to check an an object's values in typescript, based on another object's keys. The mental model is "the key exists, it's not an object, is the value in obj set, otherwise, it's an ...
3
votes
1answer
73 views

How can I re-write the conditionals for this button

I've been trying out React for a couple of days and I tried to build a button component with some conditionals. Everything works but I feel like I am not doing it the right way. Could anyone review my ...
2
votes
1answer
46 views

Rewrite BehaviorSuject that takes either localStorage or Observable in Angular

I have this code ...
5
votes
1answer
105 views

Best Practices Generics in Typescript

I'm wondering and actually playing in typescript playground with generics functions. The question is, is the code below readable? If not what kind of approach I could use to make it more typescript ...
2
votes
1answer
44 views

Computing the sum of all measures for a certain group type

I have a method that receives 2 params: first one is an array of objects of type { group1: string, group2: string, measure: number, ... } second one is a string I also have an enum GroupColumns <...
4
votes
2answers
126 views

Angular Frontend login logic

This is a follow-up to this question Node.js backend login logic. I wrote the following login Angular frontend logic for my Node.js Backend (see the previous question above). Is it any good in terms ...
2
votes
1answer
22 views

Type definitions for simple NPM package that generates OAuth 1.0a authorization header for Twitter API using native https nodejs module

I added type definitions to a simple npm package. I would love to get some feedback on ways to do better for the type definitions. The package exports a single function which returns a function that ...
2
votes
1answer
39 views

How would I name these types in a way that's accurate and not redundant?

I have a component that shows the status of a customer's billing plan. There are about seven different states it can be in, with about six props each (I've simplified it down to two for this example). ...
2
votes
0answers
53 views

The best way to handle many, different requests with custom query params

I have a list of products, I would like to filter that products e.g. by number, price, type etc. using checkboxes, selects and inputs. I get my data from REST API - using query params in GET method. ...
1
vote
2answers
45 views

How to deal with nested objects which might be string or undefined in a clean way?

So I'm parsing an object using Typescript. I am pushing a value from within the object into an array of strings. Here's the code: ...
2
votes
0answers
35 views

Storing localStorage data as part of rxjs reducer?

I use ngrx in my Angular app to state management. At a certain time I was asked to save some variable to local storage and retrieve it with first load. That made ...
7
votes
3answers
1k views

Counting words from stored .md files

The following searches recursively for all the mark down files - i. ending with the extension .md - inside a folder. It then stores the text of the files in an ...
0
votes
1answer
59 views

Refactor multiple if condition in JavaScript/TypeScript

I want to refactor this code but am wondering how I should start it. I'm not sure this code is totally against clean code or not. I'm thinking to use RxJS or a JavaScript builtin method. I'd like to ...
9
votes
4answers
1k views

Returning the last segment of a split string

I recently reviewed a PR and saw the following. const parts = someString.split('.'); return parts[parts.length - 1]; was changed to ...
-1
votes
1answer
28 views

Am I using the same Typescript variable? [closed]

I am passing a in as a parameter and want to return b. This works, however I feel like it is wrong because I shouldn't have to ...
1
vote
0answers
13 views

SequelizeJS: Abstraction of the ORM

I'm learning how to use SequelizeJS. What i found was that (at least for me) the definition of the DB model was too invasive in my code when creating object. I was thinking that the user of your model ...

1
2 3 4 5
9