Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [typescript]

A JavaScript like programming language created by Microsoft. Open source, and compiles to JavaScript.

1
vote
2answers
166 views

Is circular reference with Typescript array properties bad design?

I understand that having circular dependency can be bad design. However, I have a question regarding a certain class structure. As an example: ocean.ts import {Boat} from './boat'; export class ...
-2
votes
2answers
97 views

Typescript, CRUD Applications, and the generation of resource identifiers

I am currently trying a create a fairly simple, declarative RESTful CRUD framework, whereby I can define a resource type, and have both the API endpoint created, as well as the the functions to Create/...
1
vote
2answers
114 views

Should you rely on implicit type contracts for function returns types, or always make it explicit?

Say you're using an external library, that includes type declarations, and it has a function like: function foo(x: number) : string { //implementation } Somewhere in our code we're calling this ...
0
votes
1answer
62 views

JS Higher Order Function is even necessary in this scenario?

In Javascript, I have seen a code like: const getSomeMapper = (param1, param2, param3) (param4, param5, param6) => { // uses all these params and returns a promise } interface ...
2
votes
1answer
194 views

How to (or should I) refactor RxJS nested subscriptions with intermediate return value?

I hope this fits more here than SO because it is mostly about code design than making it work. Also, this is not tied to RxJs, but more to the reactive paradigm. (TypeScript tag is only added to make ...
0
votes
1answer
137 views

Difference between a strongly typed language and a weakly typed language with type annotations from the developer's point of view?

I understand that there are major technical differences between how a strongly typed language is compiled and how a type annotated language is compiled/transpiled. But as a developer writing in a ...
0
votes
1answer
199 views

Angular 2+ Providers/Service on Parent or Child component?

I have recently started diving deeper into Angular 7 (with Ionic 3) and I have written a lot of code so far, and I have child & parent component relationships - but never like this before. I am ...
0
votes
1answer
108 views

restricting access to a public setter

My question is how I can achieve more encapsulation in TypeScript. I have a class Item, with a public setter isOwned, but I only want to call this method in specific situations: if the item is picked ...
2
votes
1answer
358 views

Is there a convention for the Optional/Maybe monad in typescript?

Let's take the classical example of a function that may return a number or not. In typescript this can be represented like this: function f(): number | undefined {} A more elaborate way would be to ...
0
votes
1answer
64 views

How to handle different pages of a web application having different levels of access to a database model

I am working on an ASP.NET Core application that grabs a model from a database via Entity Framework, and will pass a "subset" of that model to our Angular front end. For example: I have a list of ...
1
vote
1answer
93 views

“State” pattern and encapsulation

Suppose we have the following classes: As you see, it's an implementation of the State Pattern. Basically, the Order class proxies the pay() and cancel() method calls to it's concrete OrderState ...
-1
votes
1answer
148 views

Are there any standards for flowchart data structures?

I'm often tasked with relatively complex flows that my employers will want to experiment with in regards to the amount of steps and their order. I'm a contractor and when my work is handed over to ...
3
votes
1answer
177 views

What's the best way to handle a large multi-file class in Javascript?

I have a very large class of 59 methods and about 3000 lines of code. I know that's far larger than most people would want, but the class represents a virtual machine, and most of the methods are run ...
0
votes
2answers
229 views

Why don't variables in TypeScript implicitly infer literal typing?

Given a literal type, for instance 1 | 2, assigning a value to a variable that correctly corresponds to the literal type will fail. interface SomeInterface { foo: (1 | 2); } class SomeClass ...
2
votes
3answers
165 views

Is there a pattern to describe a class that symbolises an instance of an instance of another class?

I am currently working on a project that generates videos from templates (a template being a collection of JSON files and assets). It seems natural to have a Template class that contains all the info ...
0
votes
1answer
1k views

What's the difference between “foo.spec.ts” and “foo.test.ts"?

When I use Angular CLI to generate a component, the test linked uses the logic foo.spec.ts. I am reading a tutorial where the test linked uses the logic foo.test.ts. What's the difference between “...
1
vote
2answers
4k views

Making all angular services extend a single base service

In Typescript/Angular 6 (2+), is it considered a good practice to have a base abstract http service from which derives all the application services? for example: //import the angular Http ...etc ...
-1
votes
1answer
1k views

Generic method with different arguments

In the following scenario: A factory returns an object of a logic class: ILogicClass object = factory.GetByRequirements(reqs); I then want to invoke a method and get some results which are in the ...
0
votes
1answer
181 views

UI Architecture

I'm confused in architecture solution for boolean expression tree. Business logic has algo to parse config and make a tree from such expressions. (a && b || c) && d || (e && f)...
-1
votes
1answer
96 views

How to use TypeScript to develop web applications

I've been reading a lot about Type Script lately, and it seems really interesting, but I'm having some trouble understanding how to apply this to my current workflow, so let's start with that. I ...
1
vote
1answer
1k views

Is it a good practice to log client side errors to a file

I basically want to know if it is considered a good practice to persist the errors that happen on the client side of a web application (typescript/angular for example) by logging them to files? Or if ...
1
vote
1answer
356 views

Handling Pausable Streams with RxJS

Reading a Node Stream I want to be able to receive a stream of text, and trigger the continuation of my stream. The following code solves my purposes but I recently read that we are using Subject too ...
0
votes
1answer
227 views

TypeScript - Can “Structural typing” and “OOP paradigm” co-exist?

From Type Compatibility - Introduction: Structural typing is a way of relating types based solely on their members. This is in contrast with nominal typing. Consider the following code: ...
1
vote
1answer
101 views

Ideas to deal with dependencies in a component-based web architecture

I'm spending some time lately reading and thinking about alternative ways to build web applications. One of the approaches I'm experimenting with is heavily based on OO, using TypeScript. The general ...
1
vote
1answer
759 views

Unit testing rabbitmq messaging library?

I'm having trouble figuring how I would test a library that intended to be used for communicating with another web service. For example, I have a Messenger class that initializes a connection and ...
2
votes
1answer
2k views

Designing a multi-tenant single page application for the web

I'm looking at designing a multi-tenant application (well I believe it is multi-tenant). We have a single page application, an API and common database. We have groups of users, each with their own ...
3
votes
1answer
85 views

Using an array as a member variable in a class

I have a style question for designing a class to represent a real model. Let's say I have Guide that has PointsOfInterest as a member. Would I want to do something like: class Guide { public ...
1
vote
1answer
1k views

Angular2: Service architecture + error handling

I need support for Angular2 service architectures. I am quite familiar with Angular2 but I don't see the best way to implement services, error handling and their connection with the components. I'm ...
-4
votes
1answer
832 views

How does the typescript transpile function work

Assume the following: /// file.ts var x = "hello"; x = 1; console.log(x); /// file.ts function transpile(fileName) { ... } What steps would typescript take to transpile the file? How and when ...
3
votes
0answers
220 views

Understanding Typescript's views on inheritance

I have been struggling to understand the reasons why typescript developers choose the way they implemented inheritance. What I would expect from any language supporting inheritance is these order of ...
1
vote
0answers
75 views

Capturing keyboard events for a limited time

I'm trying to code a kind of simple video game where there are two kind of players: Human Players: They enter an keyboard input CPU Players: A random input is calculated For Human Players there is a ...
1
vote
0answers
265 views

SystemJS Transpiler - where would it be used

I'm creating a project which uses SystemJS/JSPM. I'm also using TypeScript. Now TypeScript has the option of compiling JS using SystemJS Modules - which I'm doing and all is good. I've created TS ...
2
votes
1answer
226 views

In a JavaScript method signature what is meant by a return type of `typeof blahBlahBlah`?

I've seen an API list methods with both of the following signatures: methodA(...) : ReturnType methodB(...) : typeof ReturnType I understand the first but not the second. My question comes ...
1
vote
1answer
2k views

Should a method always be static if it can be?

I am using Typescript in Webstorm with Angular 2 and I am frequently getting warnings that a given method can be static. Yes, these specific methods do not depend on the state of the object they are a ...
0
votes
0answers
112 views

How is the TypeScript compiler implemented in TypeScript? [duplicate]

I was reading on the TypeScript site and saw that the TypeScript compiler is itself written in TypeScript. "The TypeScript compiler is implemented in TypeScript and can be used in any JavaScript host."...
2
votes
2answers
420 views

IoC Framework vs. DI Layer

Say we have a class structure like the following: // implementation.ts export class A implements IA { constructor(private b: IB) {} } export class B implements IB { constructor(private c: IC) ...
1
vote
2answers
663 views

Why are Promises not “awaited” by default?

In the latest version of languages like TypeScript or ECMAScript you can use async/await constructs to write code that combines the clean structure of synchronous programming with the performance ...
-1
votes
1answer
280 views

Strategy To Upgrade Frontend Javascript Code - Typescript or New Framework?

Here is my scenario. I would like advice on which path to follow, along with good reasons as to why. It would even be better if you could give an example based on experience of a similar decision but ...
3
votes
3answers
738 views

optional data in the constructor, bad practice?

Currently I have a model class that represents a user. This class has a constructor that takes an object with all user properties, used for example, when creating the user. In this case I instantiate ...
1
vote
4answers
184 views

Where should “conversion” functions be placed?

I have a type Bound as a sort of "alias" for an array of three numbers (working in TypeScript with: type Bound = [number, number, number]). I did this basically to help readability by specifying in ...
0
votes
1answer
294 views

Considerations when using Gulp to compile typescript vs using Visual Studio [closed]

We are a Microsoft shop, developing with Visual Studio. We are building a single page app, and we have elected to use Gulp to handle a lot of the script build tasks (javascript minification, css ...
10
votes
3answers
513 views

What does it mean to inject data (vs behaviour) in a class constructor, and why is that considered bad practice?

I am reading the book "Learning TypeScript" by Remo Jansen. In one section the author describes how to create a very simple proof-of-concept MVC framework including how to create the Model class and ...
3
votes
1answer
130 views

I feel like the more I improve the structure of my program I am writing a DSL [closed]

My project started out as spaghetti code. The more DRY and extensible I make my code, the more it looks like configuration files and code than runs them. Is that a good thing or does that mean I am ...
2
votes
2answers
743 views

TypeScript/ES2015: Prefer `const` instead of `let` reduces readability?

ES2015 introduced the let and const keywords, which essentially have the same semantics apart from reassignment. (const can be seen as a final variable in languages like Java.) I see the point of ...
1
vote
2answers
266 views

Finding types in TypeScript

I'm using a lot of implicit any in TypeScript. I don't quite understand how to decipher a TSD file in order to get the correct type when building off a library like express or angular. Is there a way ...
1
vote
3answers
237 views

How far should I validate user input in my own created API?

I got something here that bogs my mind a bit. Let's say I write me this API (in TS), check out some of these properties: export class MyAPI{ propertyThatShouldContainSuffix:Array<...
6
votes
2answers
255 views

Idiomatic way to write JavaScript class that maintains state and tells you when that state has changed

I am an experienced C++ developer but new to JavaScript. I want to write an ES6 JavaScript class that maintains state. How do I tell when state has changed? I can think of two ways to do this. One ...
2
votes
0answers
504 views

Why aren't there traditional namespaces in TypeScript? How do I group classes without them?

"Traditional" namespaces in the sense that Java, C#, and PHP use it. Spaces to organize related classes and sub-namespaces that span across multiple files. How do I rewire my brain to think without ...
1
vote
1answer
468 views

How do webpack and gulp complement each other?

I've started with TypeScript 2.5 years ago with Visual Studio and ASP.Net MVC. VS Web Essentials would compile ts files on save and the WebOptimizer library would bundle them together at runtime in a ...
2
votes
1answer
1k views

Is it a bad practice to compile TypeScript NodeJS app to a single JS file?

I'm currently exploring TypeScript and I was wondering why not compile the whole app to a single JS file instead of compiling every .ts file to it's corresponding .js. Example for such an app is ...