Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

1 vote
1 answer
31 views

Using string literal as a reference to named interface

I got multiple interfaces, say Int1, Int2 and so on interface Int1 {} interface Int2 {} And I want to create a registry, structured as const Registry = { "Int1": { "obj1": {}...
FFaFafy's user avatar
  • 63
1 vote
1 answer
44 views

Flatten mapped type to intersection removing the iterated union' keys used to create it

I am not sure how to better phrase the question but I hope the question title with the code below is self-explanatory, despite it might seem useless. EDIT reduced code to the bare minimum: type ...
kuus's user avatar
  • 485
0 votes
0 answers
35 views

Resolve Generic of Generic

I'm trying to create a reusable utility type in TypeScript that works with any map type conforming to a generic structure. Here's my basic setup: type SomeMap<T> = { [key: string]: T; }; I ...
Janek Eilts's user avatar
0 votes
2 answers
46 views

Can the type of a type parameter be inferred from the entries of an Array?

In the following example, is it possible for the type of P to be inferred from the entries in the props array, rather than having to define it twice? type A = { one: boolean two: number three: ...
james's user avatar
  • 4,484
0 votes
0 answers
47 views

Why does `[K in (keyof typeof SomeNumericEnum) as typeof SomeNumericEnum[K]]` result in the actual numerical index, rather than just `number`?

Given the following enum: enum Animals { CAT, DOG, PARROT, SHEEP, SALMON } The following mapped type: type AnimalsToMappedType = { [K in (keyof typeof Animals) as typeof Animals[K]]: K } ...
james's user avatar
  • 4,484
2 votes
1 answer
65 views

Why does adding parentheses remove 'readonly [x: number]: number;' from this type?

enum Animals { CAT, DOG, PARROT, SHEEP, SALMON } The following type: type AnimalsToMappedType = { [K in keyof typeof Animals]: K } Results in: type AnimalsToMappedType = { readonly [x: ...
james's user avatar
  • 4,484
0 votes
1 answer
36 views

How can I apply TS Conditional types, Mapped Types on this method?

I'm working with a TypeScript class that represents a form with various input types. Each input class has a getValue() method that returns different types based on the input. I need to create a type ...
chestacio's user avatar
2 votes
2 answers
56 views

How to generically set values of mapped type

See this following code example: type Properties = { item0: { item0: string }; item1: { item1: string }; item2: { item2: string }; item3: { item3: string }; item4: { item4: string }; }; ...
Dave Butler's user avatar
  • 1,740
0 votes
2 answers
28 views

In TypeScript how might one create a mapped, conditional type that removes properties of type string | null

Here's my final failed attempt before coming here for advice. What am I doing wrong pls ty? interface Something { id: string; name: string | null; } interface AnotherThing { id: string; name: ...
Joseph Beuys' Mum's user avatar
4 votes
0 answers
25 views

Do mapped types magically detect `null` and `undefined`? [duplicate]

If I can trust my vscode transpiler it tells me that for each of these types the result is the one I put in comments type keyOfNull = keyof null // never type keyOfundefined = keyof ...
Drax's user avatar
  • 13.1k
0 votes
2 answers
36 views

Create a RecursivePartializer

I have the following typescript code type Bar = { foo: string; prop: number; baz: { value: string; check: boolean; } } I want to create a mapped type such that type ...
robkuz's user avatar
  • 9,714
1 vote
1 answer
58 views

Is there a way to infer the keys of a mapped type when using Typescript?

I have a data structure that represents my business operations: const operations = { list: { request: "a", response: "b", }, get: { request: &...
Adam Arold's user avatar
  • 30.2k
1 vote
1 answer
118 views

Another TS 5.4 regression (i think).... how to go about fixing this type in 5.4

Recent Typescript changes (5.4.x, everything worked in 5.3.3) have made some regressions which caused a number of issues. The first one I posted about HERE. The fix proposed in that other post does ...
Dellirium's user avatar
  • 1,506
2 votes
1 answer
60 views

How to refactor long union type?

I want to create a React functional component which takes one of the predefined components as a prop and which logic depends on what component was passed in. So these are the possible names: enum ...
tnsaturday's user avatar
1 vote
1 answer
76 views

TypeScript mapped types: from list of both objects and strings to a key-value object

I'm trying to write a mapped type that takes a list which can contain both objects ("definitions") and strings. String values are limited to a set of strings that refer to existing hard ...
Even A. Rognlien's user avatar

15 30 50 per page
1
2 3 4 5
24