Reputation: 923
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!!
}
Upvotes: 0
Views: 66
Reputation: 585
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!
Upvotes: 1