Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

How to Preserve Type Inference in a Generic CRUD Class for EdgeDB in TypeScript?

I'm trying to create a generic CrudService class for EdgeDB using TypeScript. The goal is to preserve type inference for the shapes provided by EdgeDB's query methods. Here’s a minimal example of my ...
Wahib Mkadmi's user avatar
1 vote
0 answers
17 views

Create Typed Object from Two Arrays in TypeScript [duplicate]

I want to write a method in TypeScript to create an object from an array of keys and an array of values, so that each key/value pair has the type of the value. I have it mostly working: export type ...
Chris Simpson's user avatar
0 votes
1 answer
29 views

Typeguard for array

I have difficulties with typescript. One of my variable can have a string or array of string value. I would like to use a typeguard to use join function only on arrays. It looks like it ignores my ...
Dadinho's user avatar
  • 67
0 votes
1 answer
27 views

Probuf compiler with typescript vite react application

I have set up a react vite application in typescript and I woud like to use google grpc for api requests. I have a protobuf file made and I use the following command to generate the front end code for ...
Gao XiangShuai's user avatar
-1 votes
0 answers
44 views

Vue 3 - typing ref() not working during defining

I have problem with typing ref() in Vue3. Doesn't get warning from typescript when try to define more elements than was defined in type TableHeaders. Other typeof is working correctly (e.g. id: "...
bodek98's user avatar
1 vote
0 answers
15 views

Discriminating TypeScript function return type from args without using generics [duplicate]

In TypeScript, I know you can use function overloading or generics to implement polymorphism: Function overloading function add(a: number, b: number): number function add(a: string, b: string): ...
Thomas Aribart's user avatar
0 votes
0 answers
17 views

Typescript type to only include members with decorator?

I am messing around with an Angular project. Angular has a property decorator called Input, and I have run into a case where I would like to create a conditional type that excludes all members from a ...
Martin Nielsen's user avatar
0 votes
0 answers
15 views

Autopath/Path typings for lodash.get() with an additional constrain

My use case is the following: I have a table where the columns and their values are dictated by an headers object like the following: const headers = [ { key: 'data-table-select', unhidable: ...
darkbasic's user avatar
  • 343
0 votes
0 answers
18 views

Kendo react grid sort direction always asc

Problem I’m trying to implement custom sorting in a React Kendo Grid using the built-in onDataStateChange function. However, the sort direction is always stuck on 'asc' and does not switch to 'desc', ...
pavle brnovic's user avatar
2 votes
0 answers
25 views

Why doesn't Typescript infer a union type with a conditional function call? [duplicate]

In this simple case with primitives, Typescript infers the types as a union as I'd expect: function getIt(numOrStr: boolean) { return numOrStr ? 1 : "1"; } getIt(true) // 1 | "1"...
tday03's user avatar
  • 604
0 votes
0 answers
44 views

React App throwing error - Something went wrong

I want to add Options value in the reportFields List dynamically using the categoryOptions state management which get the values from the getAllCategories function. I'm going somewhere wrong but don't ...
Prasand Kumar's user avatar
0 votes
0 answers
24 views

Cannot import JS library opus-recorder in TypeScript project

In my Vite TypeScript React application I'm trying to import the Opus Recorder library (https://www.npmjs.com/package/opus-recorder). I have set this flag in tsconfig.json: "compilerOptions&...
Javide's user avatar
  • 2,627
0 votes
0 answers
93 views

"JavaScript Heap Out of Memory Error in NestJS Application on Render"

I'm deploying a NestJS application on Render, and I'm encountering a "JavaScript heap out of memory" error during runtime. Here are the details and the steps I've taken so far: Error Message:...
Raw Email's user avatar
0 votes
1 answer
51 views

Infer the return type based on a parameter

I've a function that takes an action "DELETE"|"RENAME"|"MOVE"|etc... I would like the return type to be different depending on the action fired. For example, "DELETE&...
OtpExhaustv2's user avatar
1 vote
1 answer
38 views

Typescript error based on logical AND and OR check (defensive programming)

I'm learning typescript, type safety (defensive programming), and i'm trying to implement a linked list with typescript. I don't understand why when I change the logical OR (||) to logical AND (&&...
atolz's user avatar
  • 15
0 votes
1 answer
41 views

Property 'checked' does not exist on type 'Element' while variable are NodeList

trying to select all radio input and their checked status using below code const radioInput = document.querySelectorAll("input[type=radio]"); radioInput.forEach((r) => (r.checked = r....
xkeshav's user avatar
  • 53.8k
1 vote
1 answer
94 views

Replicating the mongodb project aggregation in Typescript

My scenario: I am trying to build a typesafe wrapper around node-mongodb driver. I am having a hard time figuring out the return type for project aggregation stage. Have a look at the TS Playground ...
Abd's user avatar
  • 145
0 votes
0 answers
18 views

Module Augmentation: Modify existing property declaration

I'm customising a Material UI theme and attempting to reduce the number of `greys available for a theme I've add my types to the Color type. declare module "@mui/material" { interface ...
denski's user avatar
  • 1,988
0 votes
1 answer
33 views

How to use Typescript Generics to infer type of object property

Given this simplified example code: type People = { [key: string]: { names: (string | number)[]; }; }; const people: People = { bert: { names: ["Bert", 1], },...
Xriter's user avatar
  • 3
0 votes
0 answers
64 views

Error Setting typeRoots in tsconfig.json in a React Native project

under the compilerOptions when I add typeRoots, it gives me the below error Cannot find type definition file for 'react-native'. The file is in the program because: Entry point of type library 'react-...
Bharat Singh's user avatar
1 vote
1 answer
77 views

Type inference problem with array of generic config objects with different inner types that depend on other inner property

I'm trying to create a generic function that will create some pretty common effects, so I'll be able to pass only the config and it will create the effect. Here are some imports from NgRx: import { ...
Dmytro's user avatar
  • 90
0 votes
0 answers
14 views

How to Import Existing IAC-Generated Resources into CDK with TypeScript Without Using the Template Path?

We have a template generated from an IAC generator that we migrated to TypeScript. We want to import it into CDK while keeping the existing resources, not through the template path. How can we achieve ...
NavEn Surabhi's user avatar
0 votes
1 answer
72 views

Functions calling each other with a subset of types, leading to unintended intersection and never type

I've added a simplified version of my problem here interface TEventAssetTypeA { assetType: 'a', data: { a : string } } interface TEventAssetTypeB { assetType: 'b', data: { b : ...
Simon's user avatar
  • 504
1 vote
1 answer
43 views

Unable to initialize object property to an empty array in TypeScript despite property seeming to be of type array

I am trying to write a method in TypeScript to flatten and pick elements of paginated outputs. A demonstrative example is: const paginatedOutput: { results: number[], page: number, meta: string[] }[] =...
jack-br0wn's user avatar
1 vote
1 answer
86 views

Enforce generic type to the Typesript class only when it is given in class instantiation

I am currently refactoring a telemetry logger with two thoughts in mind: I wish to give flexibility to the users so that they can pass in optional customData object. If so, ensure that the set of ...
whoaji's user avatar
  • 21
0 votes
2 answers
49 views

How to make Typescript derive that the same property of one type is the same type

I'm trying to sort items: Item[] having properties of type 'string' or 'number' without mixing types for each property: type Item = { prop1: string; prop2: number; prop3: string; prop4: number;...
Dmitriy Metelya's user avatar
1 vote
0 answers
21 views

TypeScript: How to force Generic type that extends Record<..,..> to be of same type [duplicate]

I wrote a generic type to handle my validations. Here is a simple exemple to describe how it works type User = { name: string; cars: Car[] } type Car = { name: string } If I have an attribute in ...
James St-Pierre's user avatar
0 votes
2 answers
72 views

typescript Buffer type toString expected 0 arguments

I have this simple typescript code: const y = Buffer.from("fds") y.toString("hex") But I am getting a tsc type error on "hex" saying Expected 0 arguments, but got 1. The ...
rasen58's user avatar
  • 5,031
0 votes
0 answers
35 views

Connect the Dymo web service with Angular

I want to connect the Dymo web service with my Angular app. I have downloaded the file from here. and added to assets Dymo For that I have added this code in angular.json file. "scripts": [ ...
Malhar Naliyapara's user avatar
0 votes
0 answers
45 views

Type 'WritableDraft<User> | null' is not assignable to type 'User | null'

I've been facing this problem for a long time in my repo and I can't figure out what it's due to: ` Failed to compile. src/store/documents/documents.slice.ts TypeScript error in src/store/documents/...
Jo Cluzet's user avatar
0 votes
0 answers
50 views

How to Resolve ESLint Issues with TypeScript Module Augmentation and Merging?

I've encountered a problem with module augmentation and merging. Here's my next-auth.d.ts file for augmentation: Now, whenever I import "NextAuthOptions," ESLint flags an issue. Although I ...
zdeneklapes's user avatar
0 votes
0 answers
78 views

React Typescript Library: The Requested Module does not provide an export named 'OFIcon'

I have a React TS package. package Folder structure index.ts contains: export {default as OFIcon} from './OFIcon' Build folder structure build/esm/index.js I am using yarn link to link it to another ...
anthonyvid's user avatar
0 votes
1 answer
79 views

How do I successfully use an interface from a TypeScript file that has its own import inside it?

I'm working on a React JavaScript project with WebStorm and trying to implement type hinting for our IDEs (VS Code as well) using TypeScript interfaces and JSDoc annotations (which hopefully we'll ...
Chris Simpson's user avatar
0 votes
0 answers
16 views

How to set the type on a catch phrase using a Language server plugin

Basically I am writing a ts plugin which will type the error in a try catch. try {} catch(err: types here ){}. Does someone know how Inside of the ts language server (I am writing a plugin) I can set ...
Autumnlight's user avatar
0 votes
0 answers
56 views

How to Extend Express Request Interface to Include Mongoose Session in TypeScript?

I'm working on a Node.js project using Express and Mongoose with TypeScript. I need to attach a Mongoose session to each request to manage transactions. However, I'm encountering a TypeScript error ...
Roni Jack Vituli's user avatar
0 votes
0 answers
25 views

Redefine Axios Instance generic types

I have Axios instance: import axios from 'axios' const $api = axios.create({ withCredentials: true, baseURL: import.meta.env.VITE_API_URL }) $api.interceptors.request.use((config) => { ...
Matvey Simonenkov's user avatar
0 votes
0 answers
22 views

How to add typing for a file extension in a npm package?

I'm writing a webpack loader which for the example here processes *.foo files. I want to create typescript typings for it as follows: // index.d.ts declare module "*.foo" { const bar: ...
Axiverse's user avatar
  • 1,674
2 votes
1 answer
62 views

Why are these two types AB and CD mutually assignable in TypeScript"?

Why are the two types established by the following interfaces the same? interface AB { a?: string; b?: string; c?: string; } interface CD { c?: string; d?: string; a?: ...
daflodedeing's user avatar
0 votes
0 answers
31 views

How to get method tips?

I am wrapping the create function of zustand, but I have a problem, I can not get the methods prompt through get() when using, does anyone know how to deal with it? function create<T, M>( ...
rui he's user avatar
  • 1
1 vote
1 answer
40 views

Infer more specific type from dictionary? How to help TypeScript to infer the type?

I got this super code: export type Locale = "en" | "fr"; export type Namespace = "products" | "home"; const dict = { en: { home: { title: "My Super ...
Mike Whittom's user avatar
-1 votes
1 answer
75 views

Next.js application is there any better way to do server side rendering

I'm doing server side rendering in my next.js applicaton. This component just returns html. Is there any better way? import Feature from 'components/home/Feature/Feature'; import HeroArea from '...
shahidkhan's user avatar
1 vote
2 answers
80 views

how to infer property and value type from object types

I have an object type; I want to get a new tuple type like: [property, value], when I input the property, them typescript can infer the type of value automatically, but I can't solve the problem. ...
jimin hu's user avatar
1 vote
1 answer
44 views

Typescript tuple inference in conditional type

In the following snippets, why output1 and output2 are not both inferred as [number, number, number]? Snippet 1 : type InferTuple1<T> = T extends any[] ? [...T]: never; const func1 = <T>(...
lisztz's user avatar
  • 33
1 vote
1 answer
33 views

How to enforce a TypeScript type where only one field is a string and all others are numbers? [duplicate]

I'm working with TypeScript and need to define a type for an object where all fields are constrained to be numbers, except for one specific field named order, which should be a string. How can I ...
makmav's user avatar
  • 65
2 votes
1 answer
44 views

Validate different types in the same array in TypeScript

How MyType should be defined to ensure that each item of my array is an array composed of item of the same type? const array1: MyType = [["foo", "bar"], [42, 42], [true, false]]; //...
Maxime Lechevallier's user avatar
0 votes
0 answers
178 views

In a Next.js project using TypeScript are types automatically detected?

Learning Next.js 14 and TypeScript the typical TypeScript approach I've seen is to create a types directly with an index.d.ts file and reference all types within that file. Personal preference I'd ...
GʀᴜᴍᴘʏCᴀᴛ's user avatar
1 vote
1 answer
72 views

Typescript Union type - field type override

I have following sample code that behaviour is not clear to me. type A = { field: string } type B = { field: number } //I expect A | B is equivalent to field: A["field"] | B["...
Silverrose's user avatar
0 votes
0 answers
24 views

How to replace a generic type in a custom generic type

class X<T> { _t: T|null = null } class Y<T> { _y: T|null = null } type ReplaceT<V extends unknown<any>, NewT> = unknown // How to do this const x = new X<string&...
kennarddh's user avatar
  • 2,583
1 vote
2 answers
40 views

Why this function can accept the class type when it's not compatible with the method parameter type

Why func(x2) is valid? When x2.index require F2 to be passed into it but func only pass F1 class F1 { value: string = '' } class F2 extends F1 { value2: number = 0 } abstract class X1 { ...
kennarddh's user avatar
  • 2,583
1 vote
2 answers
35 views

Set type of return key(s) from value(s) appearing in a passed Array

I am writing an api-library and have an interface where certain keys can change depending on what is presented during the request, i.e if certain parameters are added, a key can change from a string ...
ossiggy's user avatar
  • 219

1
2 3 4 5
98