Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
41
votes
8answers
22k 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 ...
14
votes
3answers
62k 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 ...
14
votes
2answers
326 views

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 ...
13
votes
3answers
2k 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 ...
11
votes
1answer
25k 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
412 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
505 views

Lightweight Angular tooltip component

I made a small Popup component to show different error/success...etc. messages. Template: ...
10
votes
1answer
398 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 ...
9
votes
4answers
3k 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 ...
9
votes
1answer
24k 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 ...
9
votes
1answer
4k 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, ...
9
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 ...
9
votes
1answer
4k views

Angular 5 Forms - Extending Form Control

I am taking a first pass at Angular Forms with some colleagues and noticed an interesting design pattern implemented by a coworker where the FormControl is being ...
8
votes
4answers
2k views

JavaScript function that flips brackets direction

I have these strings: )hello( this has ]some text[ flip }any{ brackets even with )))]multiple[((( brackets As you can see, the brackets are all in the wrong ...
8
votes
2answers
187 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 ...
8
votes
2answers
19k 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 ...
8
votes
2answers
1k 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 ...
8
votes
0answers
148 views

React Typescript Boilerplate

I'm trying to build a React Boilerplate Using multiple tools. They are all: React, TypeScript, ESLint, Webpack, Babel, Prettier, VSCode and with Airbnb's code style guide. Actually, this is my first ...
7
votes
3answers
172 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
153 views

Accounting for floating point error when rounding

I have to implement some business logic that will round a number (typically a double) upwards. Given that this number comes from a third-party and I don't know how they come to calculate it I'm ...
6
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 ...
6
votes
1answer
56 views

Code Refactoring for Dynamic List in Angular 8

With a specific requirement of showing/hiding the pages, the following implementation has been carried out. The pages which needs to be hidden will be provided through an array ...
6
votes
2answers
2k views

Angular control for inputting latitude and longitude with validation

I've built a custom control to handle user input in a human-readable format, but save in a machine-format. It needs to have input validation, and to convert UI-input to a base format. I'm interested ...
6
votes
1answer
5k 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
326 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
13k 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
618 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. ...
6
votes
1answer
134 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
2answers
376 views

Prettier Pug Plugin

I'm the creator of the plugin Prettier Pug Plugin. Everything works fine and I have a lot of tests because I used TDD I currently have a large index.ts (permalink). In this file mainly an array of ...
5
votes
1answer
182 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 ...
5
votes
3answers
2k 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
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
1answer
165 views

Roman Number to Integer

Problem Definition Roman numerals are represented by seven different symbols: I, V, X, <...
5
votes
1answer
50 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 ...
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 ...
5
votes
1answer
13k 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 ...
5
votes
2answers
120 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
96 views

Zork look-a-like written in TypeScript

I've been working on a a text based game with a very simple battling system. There are way to many questions I can ask to get reviewed about this project, but I'll take small steps at a time (this is ...
5
votes
1answer
80 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
1answer
9k 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 ...
5
votes
1answer
5k 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
596 views

Alarm Clock with React.js

Preamble This is an Alarm Clock app. The way it works is pretty simple: you change the time by pressing the +/- buttons and set the time by pressing the play button. When the time is up, the alarm ...
5
votes
1answer
237 views

BitBoard class In TypeScript for chess logic

I'm working on writing a Chess Logic Library in JavaScript for learning purposes and was wondering how good these two slightly different implementations of a BitBoard are. The first stores the board ...
5
votes
4answers
63 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
431 views

React Context & Hooks custom Vuex like store

I've been experimenting with Hooks lately and looking more into how can I replace Redux with useContext and useReduer. For me, ...
5
votes
0answers
305 views

Reference enum values in Angular template without aliasing the enum type

Is there a way to improve this code? I'd like to use the enum type PaymentMethoddirectly in the angular template without renaming it to ...
5
votes
0answers
4k 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, ...
5
votes
0answers
46 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 ...
4
votes
2answers
1k 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 ...
4
votes
2answers
165 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 ...

1
2 3 4 5
10