Questions tagged [typescript]

Programming language created by Microsoft. Open source, and compiles to JavaScript.

Filter by
Sorted by
Tagged with
1 vote
1 answer
20 views

What should I write before the tests in Clean Architecture with TDD?

Well, we all know the main concept of TDD: write a failing test, then implement the testing component to make your test pass. I've been working on a personal project in Clean Architecture following ...
user avatar
0 votes
0 answers
30 views

Can the god object antipattern in generic typescript+react forms be avoided with dynamic imports?

Preface I looked into several other SO posts already, asking the question on how to avoid the god object pattern, but I'm not sure those articles are actually answering my question. E.g. I do know ...
user avatar
  • 131
-3 votes
1 answer
97 views

Is it a bad practice to pass instance as function parameter? [closed]

So I am learning how to use the factory function in javascript/typescript. I created a to-do list project where I had to pass the instance as a parameter to the function. I wanted to ask is it a bad ...
user avatar
0 votes
0 answers
66 views

Identify Domain Entities for a search tool interface - Clean Architecture

I am pretty new to Clean Architecture / Onion Achitecture, I actually not sure if the 2 terms are exchangeable. So it pretty clear to me, considering is a few days I am reading and study about it. It ...
user avatar
0 votes
3 answers
86 views

Decoupling command and receiver in command pattern

I'm writing a simulation of a car that can receive commands and act on them and I'm trying to implement it using the command pattern. class Car { move() { console.log('move'); } } interface ...
user avatar
12 votes
6 answers
4k views

Is it OK to have type aliases for primitive types in TypeScript?

In a project that my team is working on, we have type aliases for primitive types. The reason, I got from my team, for this is to have consistency across the codebase. For example: type FruitName = ...
user avatar
0 votes
1 answer
120 views

Changing the generic type when chaining operations

I have a class where I want to chain certain operations. The class look something like this class MyClass<T> { create<X>(fn: (_: T) => X): MyClass<X> { ... ...
user avatar
  • 119
-1 votes
2 answers
59 views

What to do when forced to initialize functions in createContext

What do I do in this situation? Do I just initialize dummy functions in place of signup, login, and logout? It seems so unnecessary since they are defined in AuthProvider. type AuthContext = { ...
user avatar
0 votes
1 answer
361 views

Where should interfaces/model definitions live? -- Clean architecture

I'm working on a Node project (in typescript) that features a variation of clean architecture. I have a pretty clear understanding of the different layers of an application and how they depend on each ...
user avatar
  • 111
0 votes
1 answer
164 views

Removing successful cases from SQS batch. Is it wrong?

I have been working on a lambda that is triggered by a SQS with a batch (let's say of 5) and has automatic retry enabled. The most common problem with this kind of setup that I have seen is that, if ...
user avatar
0 votes
1 answer
60 views

Extending TypeScript while being futureproof [closed]

C#10 Has extended the property pattern ability, I think it began since #7 EG: { Car: { Interior: pattern } } Meaning you can do some nice pattern matching even in if statements if (car_var is ...
user avatar
  • 109
1 vote
1 answer
209 views

Is usage of "global" types in typescript considered bad practice?

I'm fairly new to strongly typed languages, coming from the "jungle" world of JS and PHP. In my current Typescript project(React-Typescript), i'm struggling with a very fundamental question: ...
user avatar
  • 115
1 vote
6 answers
259 views

Liskov Substitution Principle Inconsistency? How to figure out?

Liskov Substitution Principle states: "if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of the program (...
user avatar
1 vote
5 answers
562 views

Clean architecture, Login UseCase with OAuth breaking Single responsability principle

I'm building a login system using OAuth to integrate with various social networks. The flow is very simple, first, the user is redirected to their social network to grant permission to read the ...
user avatar
1 vote
2 answers
173 views

Is it a good/bad practice to create overlapping types?

Here's a simple example: an API returns a list of possible options with the following structure: { "familystatus": [ { "Id": 1, "Name": "single&...
user avatar
  • 121
4 votes
3 answers
486 views

Steps to achieve the best code quality?

Currently I'm on a project where my objective is to obtain the best code quality. We have unit, integration & e2e testing. The e2e tests are written by the Business team in cucumber and these ...
user avatar
  • 148
6 votes
6 answers
443 views

Should a Car object be responsible for checking if it is able to run on certain Road objects?

I have 2 kinds of objects in my system, Car and Road. A Car can be of various types and have properties like tire, tire size, engine, etc. A Road can be of multiple types and have properties like ...
user avatar
  • 169
0 votes
1 answer
40 views

Pros and Cons of placing a method as static in the class or as private function outside of class when it doesn't utilize this?

I use typescript. When I write the below code ESlint throws this error: https://eslint.org/docs/rules/class-methods-use-this export class { constructor() { const result = doCalculations() ......
user avatar
  • 109
0 votes
1 answer
55 views

How are discriminated unions (e.g. in TS) used in messaging schemes?

In the documentation about discriminated unions in typescript, here it says: Discriminated unions are useful for more than just talking about circles and squares. They’re good for representing any ...
user avatar
  • 127
2 votes
1 answer
312 views

When should a variable be declared / Value assigned?

So we have quiet a big TypeScript codebase at work, where each method resides in its own file. Now in a lot of those methods the variables are often declared all together at the top/beginnng of the ...
user avatar
0 votes
2 answers
82 views

Language-independent explanation of "registration" by the IoC container

I've been reading quite a lot on the concept of Inversion of Control (IoC) and Dependency Injection (DI), and I've seen that DI often relies on an IoC container, which among other roles has to ...
user avatar
5 votes
3 answers
414 views

Qualms over the 'flexibility' advantage of using dependency injection

I'm currently studying dependency injection and I'm having some issues with the so called 'flexibility' advantage of using dependency injection. The flexibility advantage is mentioned in post ...
user avatar
0 votes
1 answer
220 views

Is a "wrong" to return anything else besides `this` in a constructor?

Is a "wrong" to return anything else besides this in a constructor? Take this TypeScript Queue sample: class Queue { private buffer: string; constructor(buffer: string = "&...
user avatar
2 votes
2 answers
448 views

Domain driven design model version

sorry for the long question, but I love DDD but there is a problem I can't seem to resolve. We have a problem when adding business rules to the aggregate root. Our architecture is mostly like this ...
user avatar
2 votes
0 answers
904 views

Setting width/height of unknown images for lazy loading

I have a site where users upload images & can all be viewed on a single page by other users. I want to lazy load images as the user scrolls instead of loading all initially. This is easy enough, ...
user avatar
-1 votes
1 answer
60 views

Angular: send form or object?

My question is about clean code or best practice. I have a big formGroup and in my opinion its more difficult to map the form to an object than to send the form to the backend. best regards
user avatar
  • 13
3 votes
0 answers
260 views

How do I architect reordering in database?

I'm building a todo list app and using react-beautiful-dnd on the frontend to allow users to reorder tasks. I'm trying to work out how to persist changes to the database when a user reorders items. ...
user avatar
2 votes
2 answers
182 views

Should base class include unused properties of sub class?

I was looking at the angular documentation and noticed this code: export class QuestionBase<T> { value: T; key: string; label: string; required: boolean; order: number; controlType: ...
user avatar
  • 177
0 votes
1 answer
112 views

Use nullable or undefineable as object type?

This come with a debate with my colleague that I'm using nullable object type. type Value = Node | null const [v0, setV0] = React.useState<Value>(null) const [v1, setV1] = React.useState&...
user avatar
  • 539
0 votes
1 answer
92 views

Preferred architecture for tree stuctured data (Angular/Typescript)

After reading some of "Clean Architecture" I got the idea that perhaps I should reconsider the way I have architected a chart of accounts/accounts object in an accounting program. I have ...
user avatar
  • 103
28 votes
14 answers
9k views

Ways to explain code when told it doesn't make sense

As a programmer I have found my code frequently elicits the reaction "I don't understand". Whenever I get this response I try my best to explain my code patiently, and not make anyone feel ...
user avatar
  • 430
4 votes
3 answers
1k views

Testing unexpected inputs for unit tests and loops?

I'm working on an enterprise that has some Angular/Typescript projects and to avoid repeating code (basically copying and pasting) between them, we decided to go for Monorepo and start write an util ...
user avatar
  • 151
2 votes
2 answers
382 views

Database Model Classes in TypeScript

I'm using Knex.js with TypeScript for database access. Table uid (UUID, auto-generated by Postgres) name (varchar) Model interface User { uid: string | null; name: string; }...
user avatar
1 vote
0 answers
359 views

Where to place the Value Object code that is shared by more than one Aggregate Root?

I have 2 Aggregate Root: One is the Lessor user, and the other is the Lessee user. class Lessor extends AggregateRoot {} class Lessee extends AggregateRoot {} Each of these Aggregate Roots has a ...
user avatar
3 votes
1 answer
151 views

Is there a simpler approach than abstract factories for handling similar, but branching, logic?

I have a medium-sized Angular-based web application that I'm currently implementing some permission components for. Overall, the areas where the permissions components will be used are virtually ...
user avatar
  • 1,317
3 votes
1 answer
5k views

Typescript and Angular 6 - Mapping Service Results to Data Transfer Objects

I think I am just look for a bit of code review advice. It might possibly be a methodology question? Essentially when I am pulling data (usually from a REST request), I generate a service, then ...
user avatar
  • 403
8 votes
3 answers
1k views

Naming of union and intersection types in TypeScript

In TypeScript, the following is called a union type: number | string and this is called an intersection type: number & string However, is the resulting type of the | not actually an intersection,...
user avatar
  • 299
8 votes
1 answer
5k views

Error handling in Nest service layer

I would like to create a REST API with NestJs. But I want to add GraphQL as another top level layer later on. So for the start I have the basic layers controller, service and TypeORM repository. Let's ...
user avatar
3 votes
2 answers
180 views

Should entities have nullable id because they're autoganerated by the database?

Suppose I have a domain entity representing a person. (Examples in TypeScript) class Person { constructor(public name: string) {} } Now, because other parts of the domain will need to reference ...
user avatar
  • 147
7 votes
1 answer
3k views

How & Should we use Clean Architecture in Front-end?

Just a little explanation: "I'm used to be a solo front-end developer in my company and using default folder-structure and way of coding which vue-cli provided, it is good for a solo developer and ...
user avatar
2 votes
0 answers
2k 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 ...
user avatar
  • 187
0 votes
1 answer
91 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 ...
user avatar
  • 103
2 votes
1 answer
217 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 ...
user avatar
  • 151
1 vote
0 answers
118 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 ...
user avatar
4 votes
1 answer
2k 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 ...
user avatar
  • 41
0 votes
1 answer
261 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 ...
user avatar
1 vote
0 answers
109 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 ...
user avatar
  • 19
1 vote
2 answers
1k 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 ...
user avatar
  • 3,319
1 vote
0 answers
30 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 ...
user avatar
  • 19
3 votes
0 answers
129 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 ...
user avatar