uwu / neptune

an experimental client mod for TIDAL
Microsoft Public License
116 stars 6 forks source link

Typescript types use enums #12

Closed Inrixia closed 10 months ago

Inrixia commented 10 months ago

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[];
};
twnlink commented 10 months ago

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

Inrixia commented 10 months ago

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

relative commented 10 months ago

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];
Inrixia commented 10 months ago

@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.

relative commented 10 months ago

dts-bundle-generator

Inrixia commented 10 months ago

Welp looks like it doesn't support enum output.

Manuly casting type safe enums will have to do.

Thanks for the help.