Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TypeScript satisfies operator for option defaults #249

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export enum OPTION_TYPE {
const DEFAULT_RULE_DOC_TITLE_FORMAT: RuleDocTitleFormat =
'desc-parens-prefix-name'; // Using this variable ensures this default has the correct type (not just a plain string).

// TODO: use TypeScript 4.9 satisfies keyword ([key in OPTION_TYPE]...) to ensure all options are included without losing type information.
export const OPTION_DEFAULTS = {
[OPTION_TYPE.CHECK]: false,
[OPTION_TYPE.CONFIG_EMOJI]: [],
Expand All @@ -83,7 +82,8 @@ export const OPTION_DEFAULTS = {
.join(','),
[OPTION_TYPE.SPLIT_BY]: undefined,
[OPTION_TYPE.URL_CONFIGS]: undefined,
};
// eslint-disable-next-line prettier/prettier -- TODO: waiting on prettier support for TypeScript 4.9: https://github.com/prettier/prettier/issues/13516.
} satisfies Record<OPTION_TYPE, unknown>; // Satisfies is used to ensure all options are included, but without losing type information.

export type GenerateOptions = {
check?: boolean;
Expand All @@ -99,6 +99,6 @@ export type GenerateOptions = {
ruleDocSectionOptions?: boolean;
ruleDocTitleFormat?: RuleDocTitleFormat;
ruleListColumns?: string;
urlConfigs?: string;
splitBy?: string;
urlConfigs?: string;
};