Skip to content

Commit 76193f2

Browse files
committed
Make task option arguments optional by requiring a defaultValue
1 parent 175394a commit 76193f2

File tree

6 files changed

+188
-205
lines changed

6 files changed

+188
-205
lines changed

v-next/core/src/internal/tasks/builders.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class NewTaskDefinitionBuilderImplementation
109109
name: string;
110110
description?: string;
111111
type?: T;
112-
defaultValue?: ArgumentTypeToValueType<T>;
112+
defaultValue: ArgumentTypeToValueType<T>;
113113
}): this {
114114
const argumentType = type ?? ArgumentType.STRING;
115115

@@ -131,10 +131,7 @@ export class NewTaskDefinitionBuilderImplementation
131131
});
132132
}
133133

134-
if (
135-
defaultValue !== undefined &&
136-
!isArgumentValueValid(argumentType, defaultValue)
137-
) {
134+
if (!isArgumentValueValid(argumentType, defaultValue)) {
138135
throw new HardhatError(
139136
HardhatError.ERRORS.TASK_DEFINITIONS.INVALID_VALUE_FOR_TYPE,
140137
{
@@ -342,7 +339,7 @@ export class TaskOverrideDefinitionBuilderImplementation
342339
name: string;
343340
description?: string;
344341
type?: T;
345-
defaultValue?: ArgumentTypeToValueType<T>;
342+
defaultValue: ArgumentTypeToValueType<T>;
346343
}): this {
347344
const argumentType = type ?? ArgumentType.STRING;
348345

@@ -364,10 +361,7 @@ export class TaskOverrideDefinitionBuilderImplementation
364361
});
365362
}
366363

367-
if (
368-
defaultValue !== undefined &&
369-
!isArgumentValueValid(argumentType, defaultValue)
370-
) {
364+
if (!isArgumentValueValid(argumentType, defaultValue)) {
371365
throw new HardhatError(
372366
HardhatError.ERRORS.TASK_DEFINITIONS.INVALID_VALUE_FOR_TYPE,
373367
{

v-next/core/src/types/tasks.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export interface TaskArgumentDefinition<T extends ArgumentType = ArgumentType> {
4545
*/
4646
export interface TaskOptionDefinition<T extends ArgumentType = ArgumentType>
4747
extends TaskArgumentDefinition<T> {
48-
defaultValue?: ArgumentTypeToValueType<T>;
48+
defaultValue: ArgumentTypeToValueType<T>;
4949
}
5050

5151
/**
@@ -201,14 +201,13 @@ export interface NewTaskDefinitionBuilder {
201201
*
202202
* The type of the argument defaults to `ArgumentType.STRING`.
203203
*
204-
* The default value, if provided, should be of the same type as the
205-
* argument.
204+
* The default value should be of the same type as the argument.
206205
*/
207206
addOption<T extends ArgumentType>(optionConfig: {
208207
name: string;
209208
description?: string;
210209
type?: T;
211-
defaultValue?: ArgumentTypeToValueType<T>;
210+
defaultValue: ArgumentTypeToValueType<T>;
212211
}): this;
213212

214213
/**
@@ -291,7 +290,7 @@ export interface TaskOverrideDefinitionBuilder {
291290
name: string;
292291
description?: string;
293292
type?: T;
294-
defaultValue?: ArgumentTypeToValueType<T>;
293+
defaultValue: ArgumentTypeToValueType<T>;
295294
}): this;
296295

297296
/**

0 commit comments

Comments
 (0)