Linked Questions

1 vote
1 answer
3k views

Edit: TypeScript now has string enums. I am looking for a string enum that can be iterated. What I tried so far: String union types: type t = "p1" | "p2" | "p3" Problem: ...
michaelmesser's user avatar
338 votes
10 answers
299k views

I'm creating a TypeScript definition file for a 3rd party js library. One of the methods allows for an options object, and one of the properties of the options object accepts a string from the list: "...
thetallweeks's user avatar
  • 7,465
166 votes
7 answers
237k views

I'm working on a definitions file for the Google maps API for TypeScript. And I need to define an enum like type eg. google.maps.Animation which contains two properties: BOUNCE and DROP. How should ...
eNepper's user avatar
  • 1,969
53 votes
7 answers
56k views

I wanted to use string enums in typescript but I can't see a support for reversed mapping in it. I have an enum like this: enum Mode { Silent = "Silent", Normal = "Normal", Deleted = "...
Kamyar Ghajar's user avatar
32 votes
4 answers
20k views

I have this type definition in TypeScript: export type xhrTypes = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "CONNECT" | "HEAD&...
marco burrometo's user avatar
16 votes
2 answers
15k views

Worded an other way: How would you type the windowState DOM property in TypeScript? SOLVED (in TypeScript 2): declare var windowState: WindowState const enum WindowState { STATE_MAXIMIZED = 1, ...
P Varga's user avatar
  • 20.4k
26 votes
1 answer
44k views

Enum definition: enum Colors { Red = "red", Blue = "blue" } How can I cast some arbitrary sting (e.g. a result from a GET request) to the enum? const color: Colors = "...
Dylan Kerler's user avatar
  • 2,207
14 votes
4 answers
12k views

I have a below enum in TypeScript: enum RoleTypes { None, Admin, SuperAdmin } When I run the following code: var roleName = RoleTypes[RoleTypes.SuperAdmin]; the value of the variable roleName ...
L.W's user avatar
  • 255
19 votes
1 answer
30k views

I am playing around with Typescript a little. Suppose I have an object such as this let colors = { RED: "r", GREEN: "g", BLUE: "b" } Now I want to convert this into an enum type enum ...
besrabasant's user avatar
  • 2,920
1 vote
3 answers
9k views

guys i wanna ask if i can create an enum that looks like this export enum CompanyMemberTypeEnum { DIRECTORS, SHAREHOLDERS, DIRECTORS_AND_SHAREHOLDERS } CompanyMemberTypeEnum.DIRECTORS ...
Nobita's user avatar
  • 23
3 votes
2 answers
4k views

Assume I have the following: export const ContentType = { Json: "application/json", Urlencoded: "application/x-www-form-urlencoded", Multipart: "multipart/form-data", }; export interface ...
Alexander Trauzzi's user avatar
3 votes
2 answers
3k views

So I've read all the posts on String Based Enums in Typescript, but I couldn't find a solution that meets my requirements. Those would be: Enums that provide code completion Enums that can be iterated ...
bersling's user avatar
  • 19.5k
1 vote
3 answers
2k views

I would like to have a set of string enums in typescript so I can do things like having the user select from a set of predefined options. I found a good solution in this answer: How to convert ...
lowcrawler's user avatar
  • 7,698
3 votes
1 answer
2k views

I am investigating the creation of a Typescript Definition file for Plotly.js. I have looked at a number of example definition files on the DefinitelyTyped repository. One question that comes to ...
Bill Kidwell's user avatar
0 votes
1 answer
526 views

I want to write a function with a parameter type guard that accepts the value from a K/V pair from an object or type... type VodTreeName = { Movie: 'movie_vod', TV: 'tv_vod', VideoStore: '...
user avatar

15 30 50 per page