Questions tagged [typescript]
Typescript is a language which is a super set of JavaScript
510
questions
0
votes
0
answers
15
views
Dispatching generic calls and types in TypeScript
I'm not sure if this is an appropriate SE site for this question. I think it belongs here better that to StackOverflow, because it is not about a single particular problem, but if you think otherwise, ...
2
votes
0
answers
30
views
Redact specific elements from JSON (for logging)
We need to implement a simple redaction function to redact (set to undefined) certain JSON elements when logging the JSON. The requirements are:
We can't modify the current JSON object, as that ...
0
votes
0
answers
33
views
Role Protection in ReactJS tsx
I asked similar question on stackoverflow, but here I am trying to get a code review. I never write a production code for frontend part, so I need some sight from the side.
I am trying to implement ...
0
votes
0
answers
25
views
Next.js TypeScript API Integration
I'm working on integrating a third party partner into our application using TypeScript, and I would appreciate some advice on best practices and potential improvements. Below, I'll outline the ...
1
vote
0
answers
17
views
Determine the maximum content size for a box such as a modal dialog
For a personal project, I try to write as much of my own code as possible, minimizing the use of libraries. I have a dialog box which contains an image and an arbitrary number of other elements that ...
5
votes
1
answer
107
views
Typescript Implementation for a fully typed map with all keys from a string union type and values to be function with return type specific to key
I was told to post my question here from a comment on my question at Stack Overflow..
With reference to my code below, I am trying to create a Map<string, Function> (...
1
vote
1
answer
112
views
Javascript Signals implementation
I've created my own implementation of signals in typescript, inspired by the proposed tc39 specification (https://github.com/tc39/proposal-signals) in the BOM. I think it would be great if I could use ...
5
votes
2
answers
87
views
TypeScript Number Set
I originally premiered this code to the internet in this StackOverflow post, and per a recommendation through one of the comments, I am reposting it here.
I am making a floating-point number set ...
0
votes
0
answers
16
views
How to make this tree-generating React hook more concise?
This hook creates a tree structure that resembles folders. You can put any item in these folders. Their ids will be stored in fileIds. If there are no folders (in ...
6
votes
5
answers
471
views
Fill missing data in between available data with default value
My raw data has values on some random times:
const rawData = [
{hour: 3, value: 3} ,
{hour: 5, value: 9} ,
{hour: 10, value: 5} ,
] as const
I would like to ...
1
vote
0
answers
134
views
Json4 parser in Typescript - Optimized
Context
This review-request is a follow-up to this question.
After the initial implementation, which focused on spec-compliance mainly, I have made some revisions to improve the performance of the ...
0
votes
0
answers
46
views
Testing whether parenthesis are correct in a string in functional JS
This is a homework exercise and therefore has no further purpose. The writing to me feels clunky, and the typescript types on addParenthesisFactory are unreadable, ...
0
votes
0
answers
39
views
Construction Permit Web App
I have a Next.js + Node.js + TypeScript + Tailwind + tRPC project whose objective is to allow a construction manager to figure out what permits are required for his renovation based on if it's an ...
1
vote
0
answers
81
views
To-do app with TypeScript backend (violations of TS best practices or unidiomatic code)
The working code in full is here.
It's a To-Do App with a TypeScript backend, written as practice for an upcoming 4-hour interview for a TypeScript backend role. My colleague and I would like to know, ...
0
votes
0
answers
33
views
Seeking Feedback on React Authentication System Implementation
I've developed a React authentication system for my application and would like to receive feedback on its correctness and potential improvements. Below is an overview of the key components and ...
0
votes
0
answers
40
views
Scaffolding through my own language (Rapid Application Development)
I'm developing a webapp where some parts that repeat, so I made source code to generate source code.
I had a lot of fun using Spring-Roo and Grails in the past but was sad that the difference between ...
2
votes
0
answers
34
views
React/Typescript/Redux Tool Kit work flow for Category component
I'm quite new to React hooks/Typescript/Redux. I'm building a mock e-Commerce website for my portfolio. I've got a component (Category) working and rendering data with no issues, it follows the below ...
0
votes
0
answers
24
views
Reusable HorizontalItemList component in React and Typescript
I'm new to React and need to display a horizontal list of items at several places in my app in differing sizes and styles.
This is a utility component I came up with:
...
2
votes
1
answer
259
views
Efficient browser `StorageEvent` handling
I have this class EfficientStorageEventProvider, which is responsible for efficient handling of StorageEvent
...
0
votes
0
answers
29
views
React equivalent to Blazor singelton pattern
I'm refactoring a code-base in React, and our design team have decided to move a button out of its usual flow and instead to a component that's very much not a descendant of the logic.
I'm relatively ...
0
votes
0
answers
15
views
Handling request failure in Next.js server-side component
I have a server-side component getting an id from the url query string to fetch data before displaying it. Everything works, but the request failure handling looks off. I'm just not sure what to put ...
1
vote
2
answers
180
views
Virtual scroller Vue component
Problem
The scrolling looks smooth on Windows, but very laggy on Linux (Webkit webview and Webkit browsers).
Any thoughts on what could be optimized or what's obviously broken?
Demo playground:
https:/...
0
votes
0
answers
36
views
Calendar Grid with layering of multiple events
My attempt at coding an adjusting calendar grid. It seems to work in most cases I've tried (although I haven't tested it exhaustively yet) but my DOM is a bit rusty and I wonder if there's better ways ...
1
vote
0
answers
32
views
Fully updating DB table with Prisma (TypeScript)
I'm often updating the Pokemon model with more detail. This detail is then sent to the UI to be displayed in the new sections I add over time.
Since there are ...
3
votes
1
answer
89
views
Random generation of points for the graphs of 3 stock share parameters
I currently studying OOP and related design patterns, and tried to implement random data generation for some stock charts using OOP as an exercise.
This code randomly generates data points for 3 ...
0
votes
1
answer
89
views
Parsing fetched data in TypeScript
I use this code to populate a DB with a batch of pokemon entries from the POKEAPI.
Since I'm using TypeScript, I added some custom parsing to use the data's type in the code. I've used a mix of ...
3
votes
0
answers
76
views
Custom AutoComplete component with Typescript Generics
I've created my own AutoComplete form element based on @nextui-org/autocomplete to be able to use it along with react-hook-form. ...
1
vote
1
answer
59
views
How to encapsulated javascript code using imutable method?
I have this code, but I need to return pure functions instead the mutating functions.
Is it possible? Perhaps using OOP? I don't know how to improve it.
I tried to return the values in each function, ...
1
vote
0
answers
50
views
Simple Todo app using latest React and TypeScript
I would like to ask your advice on the frontend code of todo app.
Main functionalities:
The app has authorization and authentication using backend.
The CRUD functionality for managing tasks
What may ...
2
votes
1
answer
100
views
Move timestamp to the next Monday 10:01 AM [closed]
I've been battling ChatGPT for hours now and can't get satisfied with this simple algorithm in TypeScript. These two (hopefully correct) TypeScript+ReactNative solutions should move the timestamp ...
0
votes
0
answers
23
views
matching generic items
Hello fellow developers
I was wondering if anyone, with more understanding of javascript, is able to detect some potential flaws or performance issues with this recursive function.
It works as ...
3
votes
1
answer
255
views
Find the closest named color
I have a .json file with name (string) and RGB (r, g, b: numbers) with 30.000 key-value pairs. I am looping the json multiple times per second to find the closest name to a given RGB color. Any idea ...
1
vote
1
answer
117
views
Simple Curry function
This is a interview practice question from BFE.dev.
Currying is a useful technique used in JavaScript applications.
Please implement a curry() function, which ...
1
vote
0
answers
113
views
Simple Table With Collaborative Editing
The following is my React code to create a simple app containing a table which can be edited by multiple people at the same time. Each client connects to a WebSocket via a custom hook. The WebSocket ...
1
vote
0
answers
47
views
Functional style dependency injection to make business logic unit-testable
My project is a blogging app, which is a recruitment assignment. It is now finished and working.
Following function handles updating a comment votes, very similar as on StackExchange sites, preventing ...
0
votes
0
answers
75
views
Typewriter component that updates span one char at a time in Next.js + TailwindCSS
I have created a Typewriter component that animates a span to display text for my portfolio website. The goal was to have an array of strings that are cycled through and an animation that types them ...
1
vote
3
answers
293
views
List consecutive days
I created this method for consecutive days to be listed with a dash, non-consecutive are separated by “and”. In my UI control I am only getting back a ...
1
vote
0
answers
69
views
Calculate total running time for movie series
Which of these 2 functions is better and more readable and why? (Both functions do the same thing).
My goal is to get the total time of a series, using the TMDB API (which has a limit of 20 different ...
0
votes
3
answers
80
views
0
votes
1
answer
206
views
Spring Boot Account API with React Frontend and Identicon Integration
I have recently been exploring React and Spring Boot, and I would greatly appreciate your feedback on a practice application that I have developed. The application consists of a Spring Boot backend ...
1
vote
1
answer
351
views
Movies App with Vue 3 and TypeScript
I have made a Movies App with Vue 3, TypeScript and The Movie Database (TMDB) API. For aesthetics, I rely on Bootstrap 5.
In src\App.vue I have:
...
1
vote
0
answers
34
views
Asynchronous Generic Resource Pooler
A personal project I'm working on needs Worker (thread) pool. The libraries I looked at were too high-level for my needs, as I simply needed access to the Worker itself while the libraries offered ...
0
votes
1
answer
40
views
Creating functions in a hierarchy where they get the same arguments
When I write code, I tend to follow functional paradigms often. The main thing I try to do is use values returned from functions.
What I notice though, is I end up having a sort of function argument ...
1
vote
0
answers
91
views
Angular Lazy Loading Component into HTML template
I want create a generic component for lazy loading other component
Demo online (click on load button)
https://stackblitz.com/edit/angular-v7xfwb
this is the code
...
5
votes
1
answer
297
views
Most compact data format for a shopping cart
I'm trying to build a format that can represent the user's cart on my website in the most compact way. The website is related to computer parts and there are 23 product categories. Each product has an ...
0
votes
1
answer
33
views
Choose a marker for the map based on the alerts it has
I need help to refactor this code, I think I can avoid the first two functions that filter the array. Also in the third part where I use the result of these two filters:
...
2
votes
0
answers
776
views
React hook to play audio with Web Audio API
My goal was to make playing sounds in my React game easy and efficient. Using <audio> tags wasn't an option, because on mobile it creates huge delays between ...
1
vote
1
answer
156
views
Function component wrapper for the js-year-calendar widget
I have this class component from the rc-year-calendar library.
...
1
vote
1
answer
135
views
Rock, paper, scissors game in expressjs typescript
This is a simple 2 player game made in NodeJS and the ExpressJS framework with typescript. I've built using OOP approach to as far of an extent as I know of it. I'm really curious as to how further ...
1
vote
0
answers
675
views
NextJS NextAuth Implementation using Custom Token Source
I am new to NextJS, it has somewhat been forced on me and the existing code was not authenticating correctly (after a period the site would hang - not return to login - this was due to the way we were ...