File tree 3 files changed +16
-10
lines changed
3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change
1
+ import type { ParameterTypeToValueType } from "./types/common.js" ;
1
2
import type { ConfigurationVariable } from "./types/config.js" ;
2
3
import type { GlobalParameter } from "./types/global-parameters.js" ;
3
4
import type {
@@ -57,11 +58,11 @@ export function overrideTask(
57
58
/**
58
59
* Defines a global parameter.
59
60
*/
60
- export function globalParameter ( options : {
61
+ export function globalParameter < T extends ParameterType > ( options : {
61
62
name : string ;
62
63
description : string ;
63
64
parameterType : ParameterType ;
64
- defaultValue : any ;
65
+ defaultValue : ParameterTypeToValueType < T > ;
65
66
} ) : GlobalParameter {
66
67
return buildGlobalParameterDefinition ( options ) ;
67
68
}
Original file line number Diff line number Diff line change 1
- import type { ParameterType } from "../types/common.js" ;
1
+ import type {
2
+ ParameterType ,
3
+ ParameterTypeToValueType ,
4
+ } from "../types/common.js" ;
2
5
import type {
3
6
GlobalArguments ,
4
7
GlobalParameter ,
@@ -10,8 +13,8 @@ import type { HardhatPlugin } from "../types/plugins.js";
10
13
* Builds a map of the global parameters, validating them.
11
14
*
12
15
* 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.
15
18
*/
16
19
export function buildGlobalParameterMap (
17
20
resolvedPlugins : HardhatPlugin [ ] ,
@@ -48,11 +51,13 @@ export function buildGlobalParameterMap(
48
51
return globalParametersIndex ;
49
52
}
50
53
51
- export function buildGlobalParameterDefinition ( options : {
54
+ export function buildGlobalParameterDefinition <
55
+ T extends ParameterType ,
56
+ > ( options : {
52
57
name : string ;
53
58
description : string ;
54
59
parameterType : ParameterType ;
55
- defaultValue : any ;
60
+ defaultValue : ParameterTypeToValueType < T > ;
56
61
} ) : GlobalParameter {
57
62
// TODO: Validate name casing
58
63
// TODO: Validate default value matches with type
Original file line number Diff line number Diff line change 1
- import type { ParameterType } from "./common.js" ;
1
+ import type { ParameterType , ParameterTypeToValueType } from "./common.js" ;
2
2
3
3
/**
4
4
* A global parameter with an associated value and a default if not provided by
@@ -13,11 +13,11 @@ import type { ParameterType } from "./common.js";
13
13
*
14
14
* If both are present, the second one takes precedence.
15
15
*/
16
- export interface GlobalParameter {
16
+ export interface GlobalParameter < T extends ParameterType = ParameterType > {
17
17
name : string ;
18
18
description : string ;
19
19
parameterType : ParameterType ;
20
- defaultValue : any ;
20
+ defaultValue : ParameterTypeToValueType < T > ;
21
21
}
22
22
23
23
/**
You can’t perform that action at this time.
0 commit comments