Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get all keys that include dash?

I am trying to workaround a deficiency in yargs library where types for configuration are produced both as kamelCase and kebab-case, e.g.

const argv = yargs
  .env('CAS')
  .help()
  .options({
    'app-path': {
      demand: true,
      type: 'string',
    },
  })
  .parseSync();

export type Configuration = typeof argv;

Now Configuration is {'app-path': string, appPath: string}.

I want to Omit dash-containing keys. However, how do I Pick all keys that contain a dash in the first place?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Template literal types to the rescue:

type A = { 'app-path': string, appPath: string }

type B = Omit<A, `${string}-${string}`>;

Playground Link

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading