Linked Questions

1 vote
1 answer
1k views

enum Foo { 'Foo' = 'A', 'Bar' = 'B' } type Value = `${Foo}` // 'A' | 'B' I'm wondering why the enum type triggers the autodispatch feature in the template string type? Does anyone know what's ...
leo's user avatar
  • 47
0 votes
0 answers
65 views

I know that an enum in Typescript compiles down to an object for runtime. I wanted to merge two enums enum EnumOne { ... }; enum EnumTwo { ... } with Object.assign(). That works. In doing so, ...
ghost23's user avatar
  • 2,262
1 vote
0 answers
44 views

abstract class A { } class B extends A { public static readonly TYPE = "A"; } interface forValue<T extends { TYPE: string }> { type: T["TYPE"] } The above works perfectly fine, now I ...
Tobiq's user avatar
  • 2,697
1 vote
0 answers
39 views

I've got the following type: type MyType = { a: string; b: number; c: boolean; } and I'd like to define a type that's missing the fields listed in the string array const keysToDrop = ['a',...
calmity's user avatar
  • 173
1 vote
0 answers
30 views

I defined two types from Enum picking up values goodValue?: `${ValueOf<typeof SampleEnum>}`; goodValueWithExclude?: `${ExcludeValue<typeof SampleEnum, 'ONE'>}`; export enum SampleEnum { ...
Mprem's user avatar
  • 11
122 votes
4 answers
94k views

I know I can define string union types to restrict variables to one of the possible string values: type MyType = 'first' | 'second' let myVar:MyType = 'first' I need to construct a type like that ...
Can Poyrazoğlu's user avatar
31 votes
2 answers
80k views

If i have something like array1: string[] = ['foo', 'bar']; and an interface like export interface MyObject { name: string; } how can I map array1 to another array of type MyObject? array2 : ...
rst's user avatar
  • 2,764
7 votes
1 answer
8k views

My goal I have a string enum E and an interface I with identical sets of keys. I want to construct a new mapped type. For each shared key k, it should use the enum value E.k as a property name. The ...
MaxAxeHax's user avatar
  • 445
5 votes
5 answers
5k views

I want to make a generic type that checks the following on an enum: all fields are strings all of the values are equal to their own keys So in which case, the following enums would be considered "...
Hank-Roughknuckles's user avatar
10 votes
2 answers
9k views

I am getting the following error when I build the following typescript code. Property 'runStaticMethod' is a static member of type 'DemoClass' Typescript Code: export class Main { constructor(...
Natarajan Ganapathi's user avatar
3 votes
1 answer
10k views

I have two string enums that have the same variants, but have different string values. They get passed to the same initial function, which accepts the entire enum (which I think I can do using typeof, ...
mihirs's user avatar
  • 63
2 votes
1 answer
5k views

I'm trying to define a type based on the value of an enum. enum E { A = "apple", B = "banana", C = "cherries" } // type EnumKey = "A" | "B&...
Jin's user avatar
  • 189
2 votes
1 answer
3k views

I have an enum like this enum A { Car = "car", Bike = "bike", Truck = "truck" } and I want to get a type that is car | bike | truck I know that keof typeof A can ...
Joji's user avatar
  • 5,846
2 votes
1 answer
3k views

I need to create a function which would expect any type of class which extends another specific class (type, not an instance) Class A{} foo(b: typeof 'extends A') Class B extends A{} Class C {} ...
tomermes's user avatar
  • 23.5k
3 votes
1 answer
3k views

I already know how to add "newable" (i.e. has constructor) constraint for function arguments (like argument for foo function below), but same techique doesn't apply to generic type parameters. Why ...
Nandin Borjigin's user avatar

15 30 50 per page