Skip to content

Commit 93281a9

Browse files
committed
Improve type for defaultValue
1 parent a72e883 commit 93281a9

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

v-next/core/src/config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ParameterTypeToValueType } from "./types/common.js";
12
import type { ConfigurationVariable } from "./types/config.js";
23
import type { GlobalParameter } from "./types/global-parameters.js";
34
import type {
@@ -57,11 +58,11 @@ export function overrideTask(
5758
/**
5859
* Defines a global parameter.
5960
*/
60-
export function globalParameter(options: {
61+
export function globalParameter<T extends ParameterType>(options: {
6162
name: string;
6263
description: string;
6364
parameterType: ParameterType;
64-
defaultValue: any;
65+
defaultValue: ParameterTypeToValueType<T>;
6566
}): GlobalParameter {
6667
return buildGlobalParameterDefinition(options);
6768
}

v-next/core/src/internal/global-parameters.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { ParameterType } from "../types/common.js";
1+
import type {
2+
ParameterType,
3+
ParameterTypeToValueType,
4+
} from "../types/common.js";
25
import type {
36
GlobalArguments,
47
GlobalParameter,
@@ -10,8 +13,8 @@ import type { HardhatPlugin } from "../types/plugins.js";
1013
* Builds a map of the global parameters, validating them.
1114
*
1215
* Note: this function can be used before initializing the HRE, so the plugins
13-
* shouldn't be consider validated. Hence, we should validate the global
14-
* parameters.
16+
* shouldn't be consider validated. Hence, we should validate the global
17+
* parameters.
1518
*/
1619
export function buildGlobalParameterMap(
1720
resolvedPlugins: HardhatPlugin[],
@@ -48,11 +51,13 @@ export function buildGlobalParameterMap(
4851
return globalParametersIndex;
4952
}
5053

51-
export function buildGlobalParameterDefinition(options: {
54+
export function buildGlobalParameterDefinition<
55+
T extends ParameterType,
56+
>(options: {
5257
name: string;
5358
description: string;
5459
parameterType: ParameterType;
55-
defaultValue: any;
60+
defaultValue: ParameterTypeToValueType<T>;
5661
}): GlobalParameter {
5762
// TODO: Validate name casing
5863
// TODO: Validate default value matches with type

v-next/core/src/types/global-parameters.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ParameterType } from "./common.js";
1+
import type { ParameterType, ParameterTypeToValueType } from "./common.js";
22

33
/**
44
* A global parameter with an associated value and a default if not provided by
@@ -13,11 +13,11 @@ import type { ParameterType } from "./common.js";
1313
*
1414
* If both are present, the second one takes precedence.
1515
*/
16-
export interface GlobalParameter {
16+
export interface GlobalParameter<T extends ParameterType = ParameterType> {
1717
name: string;
1818
description: string;
1919
parameterType: ParameterType;
20-
defaultValue: any;
20+
defaultValue: ParameterTypeToValueType<T>;
2121
}
2222

2323
/**

0 commit comments

Comments
 (0)