Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
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 ...
11
votes
1answer
139 views
+500

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 ...
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 ...
10
votes
1answer
255 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
211 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 ...
8
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 ...
8
votes
1answer
382 views

Lightweight Angular tooltip component

I made a small Popup component to show different error/success...etc. messages. Template: ...
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: ...
7
votes
2answers
565 views

Piano, output all the keys and give a scale

I've two snippets below, the first one output all the keys of a piano and the second one give me a scale when given a starting note. For those who don't know how a piano is structured here is an image ...
7
votes
3answers
8k views

Modal component in Angular 2

I've recently started to check out Angular 2 and TypeScript that comes with it, and I guess I'm kinda into it. However I'm not too sure about the whole "TypeScript way" of doing things, specifically ...
7
votes
1answer
447 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, ...
6
votes
3answers
38k views

Filtering undefined elements out of an array

I have some code that filters an array with type (Suggestion|undefined)[] into an array with type Suggestion[], but I feel it ...
6
votes
1answer
2k views

Iterating through nested array of objects

I have the following JSON list of objects, and I'm able to find the required object, and pass it back to the caller, given the id. Everything works fine, I'm just ...
6
votes
1answer
157 views

Random generator extension for VSCode

Background A VSCode extension that uses Chance.JS to generate random data types. Concerns My main concern is that there are 4 levels of function references that feels like a hack. From ...
6
votes
1answer
12k views

Audio player in Angular 2

I just built an audio player in Angular 2 using a player component and a player service. It's all working fine, I just feel like there is a much better way to do this. Should the audio object be in ...
6
votes
1answer
277 views

State Monad in TypeScript

Here's my implementation of State Monad in TypeScript, based on a canonical Haskell implementation. I would like it to get code reviewed. ...
5
votes
1answer
2k views

Natural sorting/comparing algorithm in TypeScript

This code sorts string that may contain numbers in natural order, that's it, "item 2" comes before than "item 10". It currently ignores case. I plan to implement options to handle case sensitivity and ...
5
votes
3answers
570 views

Poker Holdem Hand Evaluation 7 cards to 5

I'm building a poker Hold'em hand evaluator. Ultimately my goal after building the evaluator is to build a client on the browser but that's far from now. What I've done so far is a hand analyzer that ...
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? ...
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. ...
5
votes
1answer
30 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 (...
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. ...
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 ...
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: ...
5
votes
0answers
576 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 ...
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 ...
4
votes
1answer
5k views

Emulating constructor overloading in Typescript

I'm writing a Matrix class, and I want to be able to construct a Matrix in two ways: Supply a 2D array that the Matrix can use internally Supply the dimensions of the Matrix, and the value to fill ...
4
votes
1answer
42 views

Converting Object to Map using Generics

Problem I am loading things from the localStorage and this has to be saved as json, so it needs to have a simple Object ...
4
votes
1answer
184 views

Local weather app made with Typescript

I would like feedback on my Local weather app. This site simply gets the local weather. I refactored it from jQuery to Typescript to try to learn more about Typescript. Here is a demo: https://...
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 (...
4
votes
1answer
50 views

Searching a nested data structure for 2 attributes

So I have the following data structures ...
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 ...
4
votes
1answer
374 views

Text adventure game - text input processing

As a fun project with my wife, I decided to make a small text adventure game à la Zork. Instead of using available engines, I decided to roll my own. It won't be that hard since there are no graphics. ...
4
votes
1answer
179 views

TypeScript based Promise/A+ compliant, awaitable promise class for Node.js

This is yet another Node.js Promise implementation, but this is written in TypeScript, and it strives for type safety and clarity. The full project is located here. Feel free to download it and test ...
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
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 ...
4
votes
1answer
4k views

Parallel and Sequential array looping with async/await

Are these good implementations of parallel and sequential "extension" methods, and do they accomplish what I think they do? My understanding is that the first one is parallel because the await ...
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 ...
4
votes
1answer
209 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 ...
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
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 ...
4
votes
2answers
7k views

Automating CRUD using Repository Pattern, Web API and TypeScript

I would like a review of the following application, esp with how I'm registering and selecting the controllers. First I defined a generic Repository interface and implementation using EF 6.1.2: <...
4
votes
1answer
2k views

TypeScript definitions for Server-Sent Events

I could not find any definitions of the EventSource object that belongs to Server-Sent Events, so I create the definitions. That's how they look like: ...
4
votes
0answers
28 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 ...
4
votes
0answers
191 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 ...
3
votes
1answer
655 views

Check if JavaScript input is empty

Having a general utility function to see if the input is empty makes sense to me. Empty means different things depends on the type. I just spent ~5 minutes writing this one up, so I'm sure it's ...
3
votes
2answers
15k views

TypeScript Dictionary class

I recently implemented a dictionary class in TypeScript. I'm still new to JavaScript so I'm curious what people think about it. ...
3
votes
1answer
153 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 ...
3
votes
2answers
304 views

Quiz component with different but similar data models

I have a component with this template: ...
3
votes
2answers
87 views

Mean by properties in array of objects

I have this array of objects: ...