Questions tagged [typescript]

Typescript is a language which is a super set of JavaScript

Filter by
Sorted by
Tagged with
1
vote
0answers
126 views

Using Interface for context menu for a web application

I'm currently building an interactive web application that allows users to create flow charts using Angular2, typescript and PixiJS (the latter is a 2D rendering library). The core part of my ...
1
vote
0answers
51 views

Authenticating voting

My aim is to prevent authenticated users from voting more than once. I am using angularfire2. The code gives me the expected behavior and I was wondering the better way of doing this. The ...
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 ...
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 ...
1
vote
1answer
3k views

Call multiple services from angular2 component

This is my first Angular2 component, which makes two api calls: the first call provide the input for the the second one. The following is my attempt at this code. ...
-1
votes
1answer
158 views
-7
votes
4answers
93 views

Is this code duplication and how to avoid it when using Mathematical Operators in Typescript? [closed]

export function addition(a: number, b: number) { return a + b; } export function subtraction(a: number, b: number) { return a - b; } The code is the same ...
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 ...
2
votes
1answer
299 views

Resource pooling in TypeScript

As an exercise, and in an effort to avoid wrapping callback APIs in every node library it seems, I threw together a resource pool class. The intended usage is the following: ...
2
votes
0answers
311 views

Wrapping MongoDB Call Results in Observables

I have a number of functions that follow the basic pattern below. The intent is to provide a MongoDB implementation for a storage interface in a TypeScript application. Is there a better way to ...
2
votes
1answer
66 views

Comparing corresponding elements of two equal-length arrays

I have a helper function I wrote, but it feels like something _.lodash already does or could do if I knew the library better. ...
3
votes
2answers
357 views

Huffman code generator in Typescript

Write a program that takes any input text and produces both a frequency table and the corresponding Huffman code. Take approximately 360 words from any English document as your input text. ...
1
vote
0answers
62 views

REST request using reactive programming

The following code is an extract of a small library I wrote. Full code is available here. My question is about the following function. I added comments on each state. I'm wondering if I could do ...
1
vote
1answer
123 views

Two (or more) LRU caches for a Node.js app

Here is a caching code of a nodejs / typescript app using lru Cache module from https://www.npmjs.com/package/lru-cache. For various reason i need to setup separate caches: one for homeCache another ...
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 ...
1
vote
1answer
37 views

Sorting and tagging values in objects

Wherever the biggest number is always use the 'big' value If another number is equal to that number, use the 'big' value Set the next number in line to 'medium' If another number is equal to that ...
2
votes
1answer
94 views

Pyramid array builder

I'm developing, just for fun and learning, a TypeScript Class that creates an Array<Array<string>> that represents a pyramid. So, for ...
2
votes
1answer
859 views

Angular 2 sortable lists

I wrote a simple and small projects that present 3 buttons, each one loads a different list to the screen on the same place but not in the same time. In my HTML, I think I can maybe use some more ...
3
votes
1answer
86 views

JSON API client to manage user accounts

I have the following class in Typescript (using the Aurelia SPA-framework). ...
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 ...
1
vote
1answer
73 views

String length validation predicate

I partially refactored the code so okFields uses the extracted function checkStringLength. Now I also want problemFields() to ...
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. ...
2
votes
1answer
72 views

ReactiveX observable that uses another observable

I am trying to write an Angular service that will wrap the regular Http service and automatically make authentication calls if Bearer token is not available or invalid. Here's an illustration of a ...
1
vote
1answer
89 views

Handling post-registration action

This code is Express NodeJS code that handles post registration .post action where the user must select a custom username. The username is validated, and if valid, ...
3
votes
1answer
791 views

Mathematical equation syntax tree

I'm writing these pieces of code to parse expressions in the context of a dice rolling application for DnD. It's pretty much my first try using TypeScript and I'm ...
1
vote
0answers
18 views

Validating string lengths of link attributes

Here is a working typescript code: A modelValidator class that validates form user input. In this basic example it must check for length of form data submitted by user, and if one of the form field ...
1
vote
1answer
92 views

Retrieve unique child objects from an array

I'm using TypeScript but this example is in plain JavaScript. I have a class rank with a child-class master. I need an ordered ...
1
vote
0answers
85 views

Set the direction a Sprite faces based on its velocity

I'm learning Phaser, and decided to make a Mario-type clone. I'm writing a function that ensures the sign of the Sprites horizontal scale matches the sign of it's velocity. For a Sprite that's right-...
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 ...
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 ...
3
votes
1answer
1k views

Basic animation in Typescript

I decided to play around with doing my own super-basic animation. For a previous Javascript project, I needed the ability to flash an element. The code below is the result of me attempting to ...
0
votes
1answer
928 views

ViewModel class in Typescript

I am trying to refactor a ViewModel class because it has two methods that are really similar called updateRegions and ...
2
votes
1answer
128 views

Home page (index.php) of a website for finding products

My code is basically the home page (index.php) of a website for finding products. It accesses a database table to get a list of all countries and then populates a ...
2
votes
1answer
68 views

Building a SharePoint Search URL

I'm trying to build a URL to call the SharePoint Search REST API in TypeScript. The interesting part is building the querytext, which is done by my buildQueryText method. In my case it takes two ...
1
vote
0answers
23 views

Identify and provide a list of commands whose execution will synchronize an “official” list of objects with a “personal” list of objects

Is the intent of this code obvious / clear? Please suggest any improvements. This happens to be TypeScript, but is probably pretty familiar to anyone in the Java/C# world. These are both private ...
2
votes
0answers
2k views

Reusable REST service class for Angular2 in TypeScript

I am creating an Angular 2 web application using TypeScript. This application performs REST requests to a REST "service". For each REST resource in my service I create a separate "Service" class in ...
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 ...
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: <...
1
vote
0answers
93 views

Using interface for generated functions or just create plain functions

I was wondering which code might be better. I'm abstracting away the rote code as follows: ...
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 ...
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: ...
0
votes
1answer
80 views

Class-Definition Comparison

Whenever I needed something similar like a "Class" in JavaScript, I wrote it like this: ...
1
vote
0answers
5k views

AngularJS bookviewer directive written with Typescript and Angular-ui bootstrap

I have been working for weeks on a "BookViewer" AngularJS directive. I would like to write some blog posts on the lessons I learned in writing the directive. Before doing this I would like to ask for ...
2
votes
1answer
916 views

Is this binary search in TypeScript correct?

I need your help to see if the following binary search code is correct. I did my best to cover the corner cases. I wonder if I missed anything. The code as it is with tests (you can play with it ...
2
votes
1answer
10k views

“options” binding with an enum as data source

I need to bind a dropdown to an enum. For this I've made a key_value_pair class and I ...