Questions tagged [typescript]
TypeScript is a typed superset of JavaScript that transpiles to plain JavaScript. It adds optional types to JavaScript. This tag is for questions specific to TypeScript. It is not used for general JavaScript questions.
typescript
58
questions
1
vote
0
answers
12
views
Why does TypeScript not show never type in error when intersecting an object type with a string? [duplicate]
I am trying to understand why TypeScript does not explicitly show a never type in the error messages when intersecting an object type with a string type. Here is my code:
type Test1 = {
b: number;
...
0
votes
0
answers
6
views
How to conditionally include dependencies in a TypeScript npm package?
I have a custom npm package that includes all my regularly used functions so that I can manage them easily. However, some functions in the package use specific third-party dependencies, but users(just ...
1
vote
1
answer
13
views
Why does TypeScript not give errors for class instances not included in an array type? [duplicate]
I'm trying to ensure that a function only accepts instances of specific classes defined in an array. Here's my TypeScript code:
class Types { }
class T1 extends Types { }
class T2 extends Types { }
...
0
votes
0
answers
7
views
Add error to context with nested schemas using Zod validation
I have a Typescript application that is using Zod to validate data. The schema includes several schemas that have slightly different values with nested fields represented by other schemas as they can ...
0
votes
0
answers
7
views
Issue with Drag and Drop Elements using react-dnd in React
I am using the react-dnd library to implement a drag-and-drop feature for tasks between columns in a React application. I encountered an issue where dragging tasks behaves incorrectly:
Problem on the ...
0
votes
0
answers
23
views
Distributive on generic types
How does TS perform Omit on generic types?
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
type Data = { v: { k: 1 } }
function P<T extends Data>(...
0
votes
0
answers
23
views
When clicking print button print dialog box is not appearing to some users
When i am going to clicking print button print dialog box is working fine with my side, but some users are complaining they are not getting print dailog after clicking print button into production ...
0
votes
1
answer
13
views
How to make React-Email & Resend work with Firebase Cloud Functions
I have a Nextjs app that utilizes both React-Email, Resend & Firebase Cloud Functions. The directory structure looks like this:
I want to send an email to a user whenever a doc is created in &...
0
votes
1
answer
25
views
How to give every element of an array a ref in Typescript?
I have a component that renders multiple things, one of that is an array of spans.
Here is a part of my code:
class MyComponent ... {
private targetSpan = HTMLElement;
componentDidMount() {
//...
0
votes
2
answers
20
views
Wait for a response before loading template
I have an angular application that makes a server call on ngOnInit() and returns a result. I then use the result to populate a model in my template. My template is loading before the call is finished, ...
0
votes
0
answers
23
views
Creating a type from an object's keys and values in TypeScript
I'm trying to create a new type based on the type of a statically defined object in TypeScript. Given the following map:
const map = {
'hello': {a: 1, b: false},
'world': {b: 'hello', c: null}
...
0
votes
1
answer
39
views
Why does Typescript only widen the return type from a Promise.catch() but not from a synchronous catch?
Steps to reproduce:
Define a function that returns a promise of string or false.
Call and return an async function and return false from the catch method.
Problem:
Typescript claims it doesn't match ...
0
votes
0
answers
15
views
Vue3 Typescript Sum all values of a column in an array
I'm still very new to this programming language and I'm trying to take an array column and sum its values so I can show a total amount on the webpage.
Question #1
I was attempting to use a computed ...
0
votes
1
answer
20
views
class validator required if
I have this class
class A {
@IsString()
@MaxLength(99)
prop1: string
@IsBoolean()
prop2: boolean
}
I want it to be:
string.
required (if prop2 is true).
optional if prop2 is false.
In ...
2
votes
1
answer
39
views
Remove the `length` property from a callable type
Assume I have the following type:
export type Foo<T> = (() => T)
Is it possible to remove the length property from it while keep it callable ?
Also, using Omit, Omit<(() => T), 'length'...