uwu/neptune

Typescript types use enums

Inrixia opened this issue · 6 comments

Hia, the ts types are awesome. Would it be possible to instead of using string literals use Enum types where applicable?

Eg changing this:

mediaMetadata?: {
	tags?: ("LOSSLESS" | "SONY_360RA" | "DOLBY_ATMOS" | "HIRES_LOSSLESS" | "MQA")[];
};

to

enum MetadataTags {
	Lossless = "LOSSLESS", 
	Sont360 = "SONY_360RA", 
	Atmos= "DOLBY_ATMOS", 
	HiRes = "HIRES_LOSSLESS", 
	MQA = "MQA"
}
mediaMetadata?: {
	tags?: MetadataTags[];
};

The type definitions for TIDAL's APIs are automatically generated, string literals are just what get spat out by the generator.

Ah, what generator are you using? They generally have a option to also provide enums

the Tag type is made from an array not an enum

const tags = [
  'HIRES_LOSSLESS',
  'MQA',
  'LOSSLESS',
  'DOLBY_ATMOS',
  'SONY_360RA',
] as const;

export type Tag = (typeof tags)[number];

@relative yep I know. I'm asking what generator is used as generally there is a flag you can set to use enuns in place of string literals.

Welp looks like it doesn't support enum output.

Manuly casting type safe enums will have to do.

Thanks for the help.