Linked Questions
22 questions linked to/from Create an enum with string values
1
vote
1
answer
3k
views
String enum like type in typescript [duplicate]
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: ...
338
votes
10
answers
299k
views
How to require a specific string in TypeScript interface
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: "...
166
votes
7
answers
237k
views
How to create enum like type in TypeScript?
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 ...
53
votes
7
answers
56k
views
Reverse-Mapping for String Enums
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 = "...
32
votes
4
answers
20k
views
TypeScript type ignore case
I have this type definition in TypeScript:
export type xhrTypes = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "CONNECT" | "HEAD&...
16
votes
2
answers
15k
views
Algebraic data types in TypeScript
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,
...
26
votes
1
answer
44k
views
How can I cast a string to an enum in Typescript
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 = "...
14
votes
4
answers
12k
views
How can a enum member be aliased in TypeScript?
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 ...
19
votes
1
answer
30k
views
Converting String array to Enum in Typescript
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 ...
1
vote
3
answers
9k
views
How to create an enum with typescript and returning string
guys i wanna ask if i can create an enum that looks like this
export enum CompanyMemberTypeEnum {
DIRECTORS,
SHAREHOLDERS,
DIRECTORS_AND_SHAREHOLDERS
}
CompanyMemberTypeEnum.DIRECTORS ...
3
votes
2
answers
4k
views
How do I limit values to keys of an object?
Assume I have the following:
export const ContentType = {
Json: "application/json",
Urlencoded: "application/x-www-form-urlencoded",
Multipart: "multipart/form-data",
};
export interface ...
3
votes
2
answers
3k
views
Typescript String Based Enums
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 ...
1
vote
3
answers
2k
views
String enums in typescript
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 ...
3
votes
1
answer
2k
views
Typescript definition file for json objects with string attributes as type indicators
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 ...
0
votes
1
answer
526
views
TypeScript Mapped Type Key/Values
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: '...