Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
1
vote
1answer
191 views

Unit testing static method that imports environment file

I'm (very) new to writing unit tests and I'm wondering how I should approach testing a static method that constructs our API endpoints based on what the properties are set to in our ...
1
vote
1answer
142 views

Search Result with infinite scroll React component

I've coded a React component which should display search result and give the user the option to scroll down and retrieve 25 more objects to be displayed when the scrollbar hits the bottom. What I've ...
3
votes
0answers
101 views

Fetching user information along with user posts in Angular

Here is my code with 2 services, one is messageService which is used to get user messages: ...
2
votes
0answers
282 views

Typescript logger class

Looking for a critique of this simple logger class I'm working on in my transition to TypeScript. The purpose of the logging class is to just print to a console either info, warn or error messages. ...
0
votes
1answer
131 views

Arhitecture of Angular 7 online shop

I created online shop with angular 7 and I am not sure is good architecture. I created 5 modules: main module products shop-cart core admin I have service : ...
2
votes
1answer
80 views

List component using RXJS Angular

I have a small angular project, where I have an Article component to list articles with pagination system. The default page The placeholder loader page The main objectives are: Display the ...
1
vote
0answers
56 views

@bound decorator for TypeScript

I'm working on an angular codebase that very frequently uses constructs like: <c-whatever [action]='doSomething.bind(this)'> to pass reference to the ...
1
vote
0answers
14 views

Organization project and http-Client

I did not have experience with organization project and http-client. I suppose this is the right way. I have data-storage service where I store my data from server. ...
2
votes
1answer
67 views

Convert 'rgb()' string to hex string

The scenario is the following. I get the string from an HTML element via outerHTML and I need to convert the 'rgb(r, g, b)' part into the hexadecimal representation. I tried this with regex and it ...
2
votes
2answers
64 views

New password generation

...
1
vote
2answers
250 views

ACL express middleware implementation

I come to see you to help me improve an express middleware that allows you to control access resources by checking the rights of the user. The following code is supposed to be as generic as possible ...
3
votes
0answers
60 views

Override prototype inside of constructor of ES6 class for dependency injection

We implemented a small dependency injection mechanism which we use in our project. Now after 2 years of developing our project we need our classes to know who instantiated them via dependency ...
1
vote
1answer
39 views

TypeScript 3 form validation object

Please, correct me with anything that I say in here (The actual question is below the code). I've been quickly prototyping a project (ASP.NET Core 2.1) and haven't found the need to structure it with ...
0
votes
0answers
184 views

Functional, recursive algorithm for flattening a tree

My goals for the algorithm were to use recursion, to avoid mutation, and to decouple the tree walking from the action that we take on each node. My sense is that the result uses mode code is ...
0
votes
0answers
49 views

Deferred Iteration in TypeScript

I've published a new TypeScript library currently in beta, and was hoping to get feedback on certain aspects of it, particularly implementation details for improving the performance of deferred ...
1
vote
0answers
78 views

Nodemailer class

I created the following class for sending mail in my node.js API : ...
4
votes
0answers
189 views

Automatically generate TypeScript classes from database tables

Made a project to generate TypeScript classes from database tables, and I'm looking for input if the code is reasonable. pg and ...
2
votes
0answers
48 views

Addition of defaults to components in AngularJS

I wrote a small module in typescript that augments the angularjs registerComponent function to provide a new way of default values for the component controller. ...
1
vote
2answers
93 views

DataService that fetches data not loaded already or loads cached values

I load an array from an API that is available throughout the user's whole session. This data is unlikely to change, so it can be cached safely. I have a DataService ...
1
vote
0answers
18 views

Angular2 “Logged In State Watcher”

I have a small website I'm working on as a hobby and I created a login page/home page so far. I wanted to get the basic login/logout functionality going before filling out the main part of my site. ...
3
votes
0answers
76 views

Tic Tac Toe game (Game logic, no UI)

I've implemented a simple class for managing a Tic-Tac-Toe game's logic and state in Typescript. This code is intended to be used by a larger program; it doesn't implement any aspects of a UI. I've ...
0
votes
1answer
396 views

An Angular service to provide window and document objects

In some components and services I need the window and document. So I created a small service, that provides these two objects. ...
1
vote
1answer
86 views

Language switcher, consulting browser's localStorage

I'm using angular 6 and ngx-translate. This is my switch language function ...
3
votes
0answers
2k views

Angular async pipe with loading spinner and manual refresh

I have an Angular 6 app with the following requirements: Get data from a web service. Load the data when the page is displayed. Reload the data when the user requests a reload by through some UI, ...
1
vote
2answers
54 views

Generic function with same logic but different input structure

I have a data structure that looks like this: interface Node { originalWeight: number; currentWeight: number; } where both properties are floats between <...
6
votes
1answer
2k views

Angular directive to disable a button when clicked, allowing re-enabling as needed

I have written an Angular Directive that disables a button after it has been clicked, to prevent double posting / saving of data. This works fine in most of our use cases. However, in some situation ...
5
votes
4answers
58 views

Calculating total size of player data

I am writing a function to calculate the total size of a "player appearance". There are various "item slots" the player has, and if they are empty then 1 byte will be sent, otherwise there will be 2. ...
3
votes
0answers
115 views

Optimizing NICK binary thresholding

NICK binary thresholding essentially boils down to a convolution where the kernel at each pixel calculates the sum and squared sum (for the standard deviation). These values are then used in the ...
1
vote
1answer
57 views

Test for an array being subset of another master array

I was trying to build a small utility function to check if an array is part of other array. It's testing if an array is a subset of another master array. ...
3
votes
1answer
151 views

Angular service for fetching and passing data with observables

I have an Angular service consisting of three methods: This method makes a call to my server to get a URL ...
1
vote
1answer
6k views

Checking whether an array contains a value or another array

I'm designing an isIn method that takes a value:any and checks whether it exists in an array. It's working, but I'm wondering ...
0
votes
0answers
1k views

Checkboxes behave like radio buttons with angular

This is short Angular 5 code which works as intended: check boxes behave like radio buttons - only one can be selected at a time. Both versions of 'toggleCheckbox' works but I am interested is if ...
0
votes
2answers
2k views

JS code that search through every property in a nested object

I wrote code to search by keyword, and it will check all of the values from the object property, including an array in the object. But apparently the code is not optimized as it takes some time to ...
1
vote
0answers
304 views

Angular form data over multiple components

I have a form that I have broken into several different components in Angular. By the end of the form, all the data needs to be submitted together. My thought process was to create a provider to ...
1
vote
0answers
30 views

Firebase Plotter for Ionic

I've written this plotter for Ionic in Typescript to plot data that I push to a Firebase list. I'm new to Typescript so I'm interested in all kinds of feedback, especially on the style. First I've ...
7
votes
3answers
163 views

Find the fastest run of each year from a list of running results

Problem Explained: Imagine there is a list of running results of 1000m, like following: ...
3
votes
2answers
507 views

Creating nested objects from string

I implemented a method, to create an object based on a series of strings that are passed to it, of any depth or length. The way I implemented the solution was to map over the arguments. Assuming that ...
0
votes
1answer
378 views

Promise-based fixed delay poller with timeout

I have the following functions for polling some function periodically with a timeout ...
7
votes
1answer
439 views

Factory method done on reactjs component,

A Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. In other words, ...
2
votes
0answers
439 views

Robot on a Grid: Find a path between two corners with forbidden cells on the road

Problem statement The problem is defined in the book as following: 8.2 Robot in a Grid Imagine a robot sitting on the upper left corner of grid with r rows and <...
1
vote
1answer
130 views

Parse big JSON for reactive form

I implements big reactive form on angular5. This form get data from JSON. I use formBuilder and several nested formGroups. Every field have default value before rendering form. In console output form ...
1
vote
0answers
64 views

Redux-like implementation in TypeScript

I need to write a custom reducer utility. It should take a dictionary of reducers and a publish subject to return a state, with a dispatch method to dispatch ...
1
vote
0answers
76 views

React Text Highlighter HOC in TypeScript

I'm shifting my focus towards frontend as much as I can, but I'm still quite unsure if I'm writing good code or not. Please take a look ...
2
votes
1answer
75 views

Which will be better declaration go to with TypeScript? [closed]

This is a simple question, but during my migration to TypeScript, I'm seeing that in many cases my code could take these two directions... which one could be a better direction to go with: ...
0
votes
2answers
40 views

Picking a time based on when the app was last used

I am trying to set up a time variable as a local storage property to be retrieved when I open my app in my browser. If I open it for the first time, today, I'll set it up to today at midnight. ...
10
votes
1answer
210 views

Checkers Board Creator

A year or so ago, I wrote a checkers game for the Universal Windows Platform. Now, I wrote a web-based version of it hosted at http://checkerstreasury.azurewebsites.net. This is the first of a series ...
3
votes
0answers
31 views

The Beginnings of a HexCells Editor

This is my first foray into a full TypeScript program, and one I decided to do for fun and without the aid of jQuery. It is also my first time developing with the HTML canvas. That's quite a lot of ...
4
votes
1answer
3k views

Filtering objects according to required and preferred attributes

This my opportunity object which is a part of my angular app.component.ts file. In my template(HTML of this component) I want to ...
1
vote
3answers
51 views

Find deviations for a class in C# and present the values in a browser with TypeScript/JavaScript

We have a client that handles three different sort of licenses. These are up for renewal every year and upon renewal they need to check between 15-20 rules to see that everything is okay. They do this ...
5
votes
0answers
38 views

Macao, a General Game Playing AI library - Game state goes in, best move comes out

I'm working on a simple General Game Playing AI library. The idea is that it should work with almost any kind of game, with a minimum of configuration. At the moment, I have it working on 2 player ...