Questions tagged [typescript]

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

Filter by
Sorted by
Tagged with
-4
votes
0answers
78 views

Return result at the same line, without defining intermediate variable, pattern or anti-pattern? [duplicate]

I haven't found discussion on this topic. If there's an old discussion here where this issue has been discussed please link it, and I'll close my question. Two examples: function random(number) { ...
1
vote
0answers
57 views

Updating nested state with React Hooks and Typescript - performance vs clarity

I have some deeply nested react components. Let's limit them to 3 levels of nesting and call them Parent, Children and Grandchildren. The state for the entire app is stored in a single object in the ...
0
votes
1answer
74 views

Is my typescript controller overloaded?

I'm building a rest API using typescript and typeorm as orm. Each route of my API point's to a specific method located in a controller class. My question is about the content of this controller ...
2
votes
1answer
42 views

Web application demo mode or Introduction mode

I have a web-app with multiple functionalities and each functionality has multiple workflow/process. For example, Workflow A has Steps A => Step F, Workflow B has Steps A1 => Steps G1 and many more ...
1
vote
0answers
103 views

What to do about compilation errors if ignoring them makes the app run fine?

Updating the libraries in my Angular 8/Electron app produced compilations errors eg, in Electron's menu.ts file, Also, a few of the project external libraries contain @ts-ignore lines, suppressing ...
2
votes
1answer
126 views

Form validation code shared in the frontend and backend API?

I have a legacy Java monolithic web application. My goal is to use React on the frontend, keep Java on the backend and add an API for the frontend to use. My question is how can I write the data ...
0
votes
1answer
50 views

Any possible downsides to namespacing actions for stores

For libraries like NGRX - Actions or NGXS - Actions when creating an action you create an interface or class like so: bar-action.ts export class Foo { static type: string = 'bar-foo'; } // etc ...
1
vote
0answers
46 views

List all interfaces from a TypeScript project

I need to have compiled in a single file all the interfaces that extends a particular interface for doing some refactoring work (long story). I'm using Visual Studio 2019, but I didn't find any ...
0
votes
2answers
138 views

How can I emulate Signals and Slots found in Qt, to Javascript / Typescript Classes?

Ive brought this up with other developers, and they say while there is no obvious way forward, it seems that they all have an idea of how to go about it. Is there any way I can implement signals and ...
1
vote
0answers
21 views

Inheritance on nested components

I am creating a grid using ag-grid. Here I want to create custom dynamic cell editors. Which show different edit fields based on the value inside the cell. I got the idea from here. This question is ...
3
votes
0answers
92 views

data transfer objects between abstraction layers

I want to create an Express REST API and want to try following the clean architecture ideas. I was reading about it but didn't get the idea of the communication between the abstraction layers. Let's ...
0
votes
1answer
112 views

Advice on designing a scraper DSL

I am creating a DSL for a scraping library I am writing. I would like advice on how to design a DSL, and if the designs I have below are good ones. Apologies if this is an open-ended question, but it ...
3
votes
0answers
78 views

What's the use of interfaces vs classes in typescript?

In the company in which I work, it is customary to model entities using Interfaces when developing with Typescript. To me, it seems much more effective to model entities with classes and then ...
2
votes
2answers
597 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
154 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
131 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 ...
1
vote
1answer
71 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 ...
3
votes
1answer
440 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
348 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
294 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
149 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 ...
3
votes
1answer
1k 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
122 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
282 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
398 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
258 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
166 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 ...
1
vote
1answer
3k 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
7k 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
2k 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
195 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
104 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 ...
2
votes
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
417 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
252 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
108 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
1k 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 ...
2
votes
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
1k 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
225 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
77 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
288 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
232 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
3k 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
148 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
464 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
766 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 ...