Answers for "use enum on simple string"

0

Using enum values as string literals

public enum Country{
    SPAIN("España"),
    ITALY("Italia"),
    PORTUGAL("Portugal");


    private String value;

    Country(final String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    @Override
    public String toString() {
        return this.getValue();
    }
}
Posted by: Guest on June-02-2021
0

Create Type from String Enum

const GENDERS = ["MALE", "FEMALE", "DIVERSE"] as const;
type Gender = typeof GENDERS[number];
Posted by: Guest on September-15-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language