0

The type of ParsedParametersObject["--mode"] must be one of Parameters[ValidFirstCommandPhrases.buildProject].mode.values. Currently it has been hardcoded, so when new supported mode will be added to application we need to edit both Parameters[ValidFirstCommandPhrases.buildProject].mode.values and ParsedParametersObject.

How I can convert Parameters[ValidFirstCommandPhrases.buildProject].mode.values to valid enum-like type?

enum ValidFirstCommandPhrases {
 initializeProject = "initializeProject",
 buildProject = "buildProject"
}

export const Parameters = {
    [ValidFirstCommandPhrases.buildProject]: {
      mode: {
        name__includingDoubleNDash: "--mode",
        values: {
          development: "development",
          production: "production",
        }
      },
      debug: {
       name__includingDoubleNDash: "--debug"
     }
  }
} as const;

type ParsedParametersObject = {
    // --mode
  [Parameters[ValidFirstCommandPhrases.buildProject].mode.name__includingDoubleNDash]:
    "development" | "production"; // Hardcoded!!
}

1 Answer 1

1

An option you can use is to have a dedicated ENVIRONMENTS enum and use it as a type in ParsedParametersObject["--mode"]'s type.

See below

enum ValidFirstCommandPhrases {
 initializeProject = "initializeProject",
 buildProject = "buildProject"
}

enum ENVIRONMENTS {
    DEVELOPMENT = 'development',
    PRODUCTION = 'production'
}

export const Parameters = {
    [ValidFirstCommandPhrases.buildProject]: {
      mode: {
        name__includingDoubleNDash: "--mode",
        values: {
          development: ENVIRONMENTS.DEVELOPMENT,
          production: ENVIRONMENTS.PRODUCTION,
        }
      },
      debug: {
       name__includingDoubleNDash: "--debug"
     }
  }
} as const;

type ParsedParametersObject = {
    // --mode
  [Parameters[ValidFirstCommandPhrases.buildProject].mode.name__includingDoubleNDash]: 
ENVIRONMENTS;
}

Hope it helps!

Sign up to request clarification or add additional context in comments.

1 Comment

It will! Thank you for the answer!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.