Fixed modifier typing
This commit is contained in:
parent
72dbc2da90
commit
1976628b16
1 changed files with 21 additions and 36 deletions
|
@ -46,27 +46,22 @@ export type ModifierFromOptionalParams<T, S> = T extends undefined
|
||||||
: WithRequired<Modifier, "revert" | "enabled" | "description">;
|
: WithRequired<Modifier, "revert" | "enabled" | "description">;
|
||||||
|
|
||||||
/** An object that configures an additive modifier via {@link createAdditiveModifier}. */
|
/** An object that configures an additive modifier via {@link createAdditiveModifier}. */
|
||||||
export interface AdditiveModifierOptions<
|
export interface AdditiveModifierOptions {
|
||||||
T extends Computable<CoercableComponent> | undefined,
|
|
||||||
S extends Computable<boolean> | undefined
|
|
||||||
> {
|
|
||||||
/** The amount to add to the input value. */
|
/** The amount to add to the input value. */
|
||||||
addend: Computable<DecimalSource>;
|
addend: Computable<DecimalSource>;
|
||||||
/** Description of what this modifier is doing. */
|
/** Description of what this modifier is doing. */
|
||||||
description?: T;
|
description?: Computable<CoercableComponent> | undefined;
|
||||||
/** A computable that will be processed and passed directly into the returned modifier. */
|
/** A computable that will be processed and passed directly into the returned modifier. */
|
||||||
enabled?: S;
|
enabled?: Computable<boolean> | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a modifier that adds some value to the input value.
|
* Create a modifier that adds some value to the input value.
|
||||||
* @param optionsFunc Additive modifier options.
|
* @param optionsFunc Additive modifier options.
|
||||||
*/
|
*/
|
||||||
export function createAdditiveModifier<
|
export function createAdditiveModifier<T extends AdditiveModifierOptions>(
|
||||||
T extends Computable<CoercableComponent> | undefined,
|
optionsFunc: () => T
|
||||||
S extends Computable<boolean> | undefined,
|
): ModifierFromOptionalParams<T["description"], T["enabled"]> {
|
||||||
R = ModifierFromOptionalParams<T, S>
|
|
||||||
>(optionsFunc: () => AdditiveModifierOptions<T, S>): R {
|
|
||||||
return createLazyProxy(() => {
|
return createLazyProxy(() => {
|
||||||
const { addend, description, enabled } = optionsFunc();
|
const { addend, description, enabled } = optionsFunc();
|
||||||
|
|
||||||
|
@ -95,31 +90,26 @@ export function createAdditiveModifier<
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
}) as unknown as R;
|
}) as unknown as ModifierFromOptionalParams<T["description"], T["enabled"]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An object that configures an multiplicative modifier via {@link createMultiplicativeModifier}. */
|
/** An object that configures an multiplicative modifier via {@link createMultiplicativeModifier}. */
|
||||||
export interface MultiplicativeModifierOptions<
|
export interface MultiplicativeModifierOptions {
|
||||||
T extends Computable<CoercableComponent> | undefined,
|
|
||||||
S extends Computable<boolean> | undefined
|
|
||||||
> {
|
|
||||||
/** The amount to multiply the input value by. */
|
/** The amount to multiply the input value by. */
|
||||||
multiplier: Computable<DecimalSource>;
|
multiplier: Computable<DecimalSource>;
|
||||||
/** Description of what this modifier is doing. */
|
/** Description of what this modifier is doing. */
|
||||||
description?: T;
|
description?: Computable<CoercableComponent> | undefined;
|
||||||
/** A computable that will be processed and passed directly into the returned modifier. */
|
/** A computable that will be processed and passed directly into the returned modifier. */
|
||||||
enabled?: S;
|
enabled?: Computable<boolean> | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a modifier that multiplies the input value by some value.
|
* Create a modifier that multiplies the input value by some value.
|
||||||
* @param optionsFunc Multiplicative modifier options.
|
* @param optionsFunc Multiplicative modifier options.
|
||||||
*/
|
*/
|
||||||
export function createMultiplicativeModifier<
|
export function createMultiplicativeModifier<T extends MultiplicativeModifierOptions>(
|
||||||
T extends Computable<CoercableComponent> | undefined,
|
optionsFunc: () => T
|
||||||
S extends Computable<boolean> | undefined,
|
): ModifierFromOptionalParams<T["description"], T["enabled"]> {
|
||||||
R = ModifierFromOptionalParams<T, S>
|
|
||||||
>(optionsFunc: () => MultiplicativeModifierOptions<T, S>): R {
|
|
||||||
return createLazyProxy(() => {
|
return createLazyProxy(() => {
|
||||||
const { multiplier, description, enabled } = optionsFunc();
|
const { multiplier, description, enabled } = optionsFunc();
|
||||||
|
|
||||||
|
@ -147,31 +137,26 @@ export function createMultiplicativeModifier<
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
}) as unknown as R;
|
}) as unknown as ModifierFromOptionalParams<T["description"], T["enabled"]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An object that configures an exponential modifier via {@link createExponentialModifier}. */
|
/** An object that configures an exponential modifier via {@link createExponentialModifier}. */
|
||||||
export interface ExponentialModifierOptions<
|
export interface ExponentialModifierOptions {
|
||||||
T extends Computable<CoercableComponent> | undefined,
|
|
||||||
S extends Computable<boolean> | undefined
|
|
||||||
> {
|
|
||||||
/** The amount to raise the input value to the power of. */
|
/** The amount to raise the input value to the power of. */
|
||||||
exponent: Computable<DecimalSource>;
|
exponent: Computable<DecimalSource>;
|
||||||
/** Description of what this modifier is doing. */
|
/** Description of what this modifier is doing. */
|
||||||
description?: T;
|
description?: Computable<CoercableComponent> | undefined;
|
||||||
/** A computable that will be processed and passed directly into the returned modifier. */
|
/** A computable that will be processed and passed directly into the returned modifier. */
|
||||||
enabled?: S;
|
enabled?: Computable<boolean> | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a modifier that raises the input value to the power of some value.
|
* Create a modifier that raises the input value to the power of some value.
|
||||||
* @param optionsFunc Exponential modifier options.
|
* @param optionsFunc Exponential modifier options.
|
||||||
*/
|
*/
|
||||||
export function createExponentialModifier<
|
export function createExponentialModifier<T extends ExponentialModifierOptions>(
|
||||||
T extends Computable<CoercableComponent> | undefined,
|
optionsFunc: () => T
|
||||||
S extends Computable<boolean> | undefined,
|
): ModifierFromOptionalParams<T["description"], T["enabled"]> {
|
||||||
R = ModifierFromOptionalParams<T, S>
|
|
||||||
>(optionsFunc: () => ExponentialModifierOptions<T, S>): R {
|
|
||||||
return createLazyProxy(() => {
|
return createLazyProxy(() => {
|
||||||
const { exponent, description, enabled } = optionsFunc();
|
const { exponent, description, enabled } = optionsFunc();
|
||||||
|
|
||||||
|
@ -199,7 +184,7 @@ export function createExponentialModifier<
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
}) as unknown as R;
|
}) as unknown as ModifierFromOptionalParams<T["description"], T["enabled"]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue