Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#54114 fix(prettier): all default value s…
Browse files Browse the repository at this point in the history
…hould be optional by @JounQin

* fix(prettier): all `default` value should be optional

* test: add test case
  • Loading branch information
JounQin authored Jul 1, 2021
1 parent dd887b2 commit cc5ef96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
20 changes: 13 additions & 7 deletions types/prettier/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Christopher Quadflieg <https://github.com/Shinigami92>
// Kevin Deisz <https://github.com/kddeisz>
// Georgii Dolzhykov <https://github.com/thorn0>
// JounQin <https://github.com/JounQin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.7

Expand Down Expand Up @@ -360,9 +361,14 @@ export interface SupportOptionRange {

export type SupportOptionType = 'int' | 'boolean' | 'choice' | 'path';

export type CoreCategoryType = 'Config' | 'Editor' | 'Format' | 'Other' | 'Output' | 'Global' | 'Special';

export interface BaseSupportOption<Type extends SupportOptionType> {
readonly name?: string;
since: string;
/**
* Usually you can use {@link CoreCategoryType}
*/
category: string;
/**
* The type of the option.
Expand All @@ -387,30 +393,30 @@ export interface BaseSupportOption<Type extends SupportOptionType> {
}

export interface IntSupportOption extends BaseSupportOption<'int'> {
default: number;
default?: number;
array?: false;
range?: SupportOptionRange;
}

export interface IntArraySupportOption extends BaseSupportOption<'int'> {
default: Array<{ value: number[] }>;
default?: Array<{ value: number[] }>;
array: true;
}

export interface BooleanSupportOption extends BaseSupportOption<'boolean'> {
default: boolean;
default?: boolean;
array?: false;
description: string;
oppositeDescription?: string;
}

export interface BooleanArraySupportOption extends BaseSupportOption<'boolean'> {
default: Array<{ value: boolean[] }>;
default?: Array<{ value: boolean[] }>;
array: true;
}

export interface ChoiceSupportOption<Value = any> extends BaseSupportOption<'choice'> {
default: Value | Array<{ since: string; value: Value }>;
default?: Value | Array<{ since: string; value: Value }>;
description: string;
choices: Array<{
since?: string;
Expand All @@ -420,12 +426,12 @@ export interface ChoiceSupportOption<Value = any> extends BaseSupportOption<'cho
}

export interface PathSupportOption extends BaseSupportOption<'path'> {
default: string;
default?: string;
array?: false;
}

export interface PathArraySupportOption extends BaseSupportOption<'path'> {
default: Array<{ value: string[] }>;
default?: Array<{ value: string[] }>;
array: true;
}

Expand Down
5 changes: 5 additions & 0 deletions types/prettier/prettier-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ const plugin: prettier.Plugin<PluginAST> = {
array: true,
default: [{ value: ['./pathA.js', './pathB.js'] }],
},
testNoDefaultOption: {
since: '1.0.0',
type: 'path',
category: 'Test',
}
},
};

Expand Down

0 comments on commit cc5ef96

Please sign in to comment.