Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
2
votes
1answer
741 views

code duplication in conditional Promise

I am writing a function in Typescript that involves checking a condition, doing some extra processing if the condition is satisfied, and then doing the bulk of the job. Here's the catch: the extra ...
0
votes
2answers
785 views

Angular2/4 broadcast service using RxJS

I am no expert in RxJS as I am still learning my way around the new paradigm of Observable/Subject. I was trying to implement a broadcast service (based on NgRadio) that allows a new subscriber to ...
3
votes
0answers
207 views

Vehicle price calculation Angular service

I have written a service which can generate prices from inputs. However, I feel that this can be "refactored" because it is not flexible enough. The code "works" however I feel if I could make this ...
3
votes
1answer
772 views

Static helper function to set a property on another object

A situation has come up in which we have a block of code that will be repeated in multiple files, and this block of code has to: Create some object based on the values of other controls/properties. ...
2
votes
1answer
338 views

Typescript: Recursion file-system lookup

Previously I asked a question to find the best practice of recursively running a function to retrieve all import/export statements of files in NodeJs here. After some discussion I'm not satisfied yet,...
1
vote
0answers
55 views

Recursive time formatter

This is small utility class I made format.utility.ts. There are some other one off utility methods in here I removed for this. The one in question is ...
2
votes
1answer
4k views

Angular 2 window service that listens for 'click away'

This is the angular service I wrote window.service.ts. ...
1
vote
0answers
63 views

React higher-order component: withHigherHandlers

I'm trying to create a helper method just like recompose's withHandlers, but I need to pass my handlers an extra argument. Here's the code: ...
-1
votes
1answer
31 views

Make one method from two pieces of code with continue and return operators? [closed]

The same code pieces in five methods are: ...
2
votes
0answers
1k views

Creating a logger that wraps around winston and express-winston

I am trying to create a logger wrapper around winston and express-winston (enables middleware error log) that is configurable . How could i improve this code? //logger.ts ...
3
votes
1answer
1k views

Angular 2 service to upload a batch job and poll for results

I have to write a web interface for one of my homebrew projects. Since I'm not familiar with HTML and CSS I've decided to take heavy duty framework such as Angular 2. This is my first experiment - I'm ...
2
votes
0answers
23 views

Adjust Hours on UTC String to Account for TimeZoneOffset

I have a library that provides a time-picker HTML element, which takes a UTC string as an input. The timepicker adjusts any UTC string it receives to local time. So, for example, if it takes ...
0
votes
1answer
149 views

Implementing a 'TreeGraph' which extends a normal graph

I'm currently trying to build an interactive technology tree for Stellaris. Which normally doesn't come with a tree view. Stellaris is like Civilization 5, where the tree isn't actually a tree, as it ...
0
votes
1answer
447 views

Web developer profile page in Angular 2+

I recently took a class on Angular 2+ at Code School. I then rebuilt my homepage using Angular 4. I would greatly appreciate if any developer experienced with Angular 2+ can check out my code on ...
2
votes
1answer
98 views

Filtering array of objects

I built a search bar that will filter an array of objects. But I feel like I can improve it. When I filter, I want to filter the first and last name case insensitive, then sort the names and then map ...
2
votes
1answer
341 views

Function to determine the appropriate dimensions for a close button

How can I reduce the cyclomatic complexity of this CloseButtonDimensions function? ...
3
votes
0answers
73 views

Optionally disabling a call-tracing decorator in Typescript

I have a Typescript decorator that traces method calls. The decorator can be applied at both the class level and method level. I want to disable the decorator in production. Is this code the most ...
4
votes
1answer
68 views

Getting hex colours from a image

I am trying to get the hex colours from an image. The problem I am having is that for some reason randomly the code causes high CPU usage, which times out the browser and I am not sure how to optimise ...
3
votes
0answers
121 views

React.JS functional paradigm

I have some (minimal) experience with the functional programming paradigm and I'm new to React.js and reactive programming. I'm trying to get a flavour for the React.js philosophy and I keep seeing ...
1
vote
1answer
874 views

Angular retrieve data through Pipe

I have recently come up with an idea to retrieve additional data through Pipe, and I am not sure if I created a cool solution or terrible abomination. I will try to present the problem and my solution....
1
vote
1answer
548 views

Filtering an array according to 7 checkboxes in a form

I am filtering an array whenever checkboxes are checked. ...
4
votes
1answer
208 views

Simple Cookie Service - Returns value of cookie based on cookie name passed in

Introduction So I have written a simple service that, when loaded, reads all of the cookies in the document, reduces them to a simple object where the cookie name is the key, and the cookie value is ...
3
votes
1answer
3k views

Best solution for returning results from a generic Typescript service

I am beginning to develop a common data service that can be used by other services. Specifically, this service will be injected into a generic abstract application service. I am trying to figure out ...
4
votes
1answer
55 views

Web app that splits a URL graphically

I wrote this web app that splits a URL graphically so that its parts can be customized to create a new URL. https://github.com/ibrahim-islam/urlpad. The app currently works as expected for usual URls ...
4
votes
1answer
8k views

RxJS Observable with initial value

Is it possible to get rid of the BehaviourSubject to have an Observable with an initial value? Another thing I don't like is that I'm using getValue() and then modify this value and push it with next ...
4
votes
1answer
925 views

Monad Implementation in Typescript

Having been introduced to monads through Scala, I am trying to add the generalized design pattern to my toolkit by implementing it in a language I use more regularly (typescript). My tests pass (...
1
vote
1answer
3k views

Angular 2 / rxjs chaining HTTP calls

I have a registration form. Step 1 user creates an account. As user creates an account I need to authenticate user with the created account. in my account.service.ts I have following. Is this the ...
1
vote
1answer
82 views

Inheritance: declare a method that returns the current instance class

I have a Vector and 2-dimensional Vector, defined as follows: ...
1
vote
1answer
1k views

Angular 2 Component conditionally displaying a list of elements from an array

This Angular component displays a list of polls that are fetched from the server and has a slide toggle giving the authenticated user the option to display all polls or just the ones that the user has ...
3
votes
1answer
2k views

Object Literal Pattern in Typescript

My goal is to use the object literal pattern in TypeScript. Here is an example of the object literal pattern in JavaScript. I created a simple example of the object literal pattern in TypeScript. ...
3
votes
2answers
569 views

Angular Guards - Firebase loggedInAndVerified

I have an app that I want to limit to both logged in and verified users. I was able to make two separate guards (logged-in.guard.ts and ...
4
votes
1answer
2k views

Jasmine tests for TypeScript class's pure functions

Instead Of Intro I am a .NET developer who has recently moved to front-end realms. Unit testing was never a strong side of mine, but what I learnt is that the test code has to be of highest quality ...
5
votes
2answers
106 views

Make JSON based on available fields

I am trying to create a filter string according to the fields available with the following code, how could i improve the following with a switch case or better way? ...
1
vote
1answer
53 views

TypeScript, checking for keys and subkeys and its variants

How to reduce code size? ...
2
votes
3answers
6k views

Angular2 Route Interceptor

WARNING: Please see @MgSam's answer for a fatal bug in my original code. He has a revised version that fixes the bug. I have made a route interceptor service that has an API to hook into every event ...
3
votes
3answers
381 views

Classify the urgency by comparing the current time to two timestamps

I'm currently working on a typescript-class with this method: ...
38
votes
8answers
16k views

Deck of cards as an interview exercise

I was asked to write a test code for an exercise for a job I applied for. I was rejected, and I didn't know why. And I want to ask your opinions about my code. The exercise is like that: Write a ...
5
votes
1answer
4k views

Making multiple http request Angular2

I need to get some ids from contacts and contactgroups to be able to collect the data. My example works but i dont know if this is the way to go. ...
2
votes
1answer
5k views

Angular4 MultiSelect Component

I wrote an Angular 4 app and a part of it was a multiselect component. The multiselect component acts like a basic HTML select but gives you the ability to select more than one option, typeahead, and ...
3
votes
0answers
410 views

Publishing angular-cli component library to npm or like

I've found a lot of blog posts that seem to suggest publishing a library TypeScript (as source) and all to npm or to a private repository. It feels like we should be doing some transpiling first and ...
2
votes
0answers
209 views

Alpha Beta Pruning

I'm implementing alpha-beta pruning for a chess engine in TypeScript Here's the code: ...
2
votes
1answer
58 views

Mapping a user's availabilities

So we're starting to use Typescript for a new project at work. Part of the application allows a user to retrieve their future availabilities (present/absent/possibly present), for planning purposes. ...
4
votes
3answers
100 views

Check for Scrabble double letter bonus

This function checks if the cell of a Scrabble board is a double letter bonus. It has a 23 cyclomatic complexity, which is higher than the threshold of 20. I don't know how to do it another way, I ...
5
votes
1answer
99 views

Angular component for a system to store student test scores

I am designing a system and in it there is a view where teachers can see a summary of test data on students. Here is the component of it: ...
4
votes
1answer
749 views

Handling combinations of optional parameters for an Angular filter pipe

This is a simple implementation of an ng2 filter pipe, which can currently take 2 optional facets: <string>status and ...
10
votes
1answer
251 views

Javascript/Typescript anagram String search

I've created a random word generator which allows me to create random words/anagrams. Then I've created Anagram search app to find the angarams when user start typing in inbox. Could you review ...
10
votes
1answer
21k views

Angular 2 clock with RxJS Observable

I'm fairly new to Angular 2 and I started off with creating a clock for my app. I tried to stick to the official documentation tutorial. Folder structure: The CSS file is still empty and the HTML is ...
5
votes
0answers
575 views

Wrapping IndexDB with RxJs

I find IndexedDB cumbersome and want to wrap the functionality with rxjs observables. I've come up with an angular2 service that seems to fit the bill, but I'm wondering if I'm using the observables ...
1
vote
1answer
432 views

TypeScript JSON-Array Validator

For my latest app I wanted to be able to code the front-end first, without having to do super extensive documentation and without forgetting my data types later on while coding the back-end. I thus ...
2
votes
2answers
85 views

Represent a person who has different roles for different offices

People have different types of roles depending on the office they are working at. For example, a person has two roles (cashier,cleaner) at OfficeMax and five roles(manager,security,etc) at OfficeLess. ...