Skip to content

Mapping enum values to something else #8

@Offirmo

Description

@Offirmo

I have an Enum and I'm trying to map the values to something else:

const UrlCategory = Enum(
	'pro', // .com, .co.xyz, .biz
	'geek', // .net, .io
	'perso', // .me, .name
	'other',
	'special', // not internet, ex. chrome settings, ftp...
)
type UrlCategory = Enum<typeof UrlCategory>

const UrlCategoryColorMapping = {
	UrlCategory.pro: 'blue',
	UrlCategory.geek: 'yellow',
	UrlCategory.perso: 'pink',
	UrlCategory.other: 'green',
	UrlCategory.special: 'black',
}

This is refused by the compiler on the ground of syntax error + error TS1117: An object literal cannot have multiple properties with the same name in strict mode.

Do you have any suggestion ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions