Fix remaining typing issues with formula typing change

This commit is contained in:
thepaperpilot 2023-04-22 18:08:38 -05:00
parent 6363062ce6
commit 7a81157bcc
3 changed files with 15 additions and 41 deletions

View file

@ -2,11 +2,7 @@ import type { OptionsFunc, Replace } from "features/feature";
import { setDefault } from "features/feature"; import { setDefault } from "features/feature";
import type { Resource } from "features/resources/resource"; import type { Resource } from "features/resources/resource";
import Formula from "game/formulas/formulas"; import Formula from "game/formulas/formulas";
import { import { InvertibleFormula, InvertibleIntegralFormula } from "game/formulas/types";
IntegrableFormula,
InvertibleFormula,
InvertibleIntegralFormula
} from "game/formulas/types";
import type { BaseLayer } from "game/layers"; import type { BaseLayer } from "game/layers";
import type { DecimalSource } from "util/bignum"; import type { DecimalSource } from "util/bignum";
import Decimal from "util/bignum"; import Decimal from "util/bignum";
@ -23,9 +19,7 @@ export interface ConversionOptions {
* The formula used to determine how much {@link gainResource} should be earned by this converting. * The formula used to determine how much {@link gainResource} should be earned by this converting.
* The passed value will be a Formula representing the {@link baseResource} variable. * The passed value will be a Formula representing the {@link baseResource} variable.
*/ */
formula: ( formula: (variable: InvertibleIntegralFormula) => InvertibleFormula;
variable: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula
) => InvertibleFormula;
/** /**
* How much of the output resource the conversion can currently convert for. * How much of the output resource the conversion can currently convert for.
* Typically this will be set for you in a conversion constructor. * Typically this will be set for you in a conversion constructor.

View file

@ -201,9 +201,7 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
* Creates a formula that evaluates to a constant value. * Creates a formula that evaluates to a constant value.
* @param value The constant value for this formula. * @param value The constant value for this formula.
*/ */
public static constant( public static constant(value: ProcessedComputable<DecimalSource>): InvertibleIntegralFormula {
value: ProcessedComputable<DecimalSource>
): InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula {
return new Formula({ inputs: [value] }); return new Formula({ inputs: [value] });
} }
@ -211,9 +209,7 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
* Creates a formula that is marked as the variable for an outer formula. Typically used for inverting and integrating. * Creates a formula that is marked as the variable for an outer formula. Typically used for inverting and integrating.
* @param value The variable for this formula. * @param value The variable for this formula.
*/ */
public static variable( public static variable(value: ProcessedComputable<DecimalSource>): InvertibleIntegralFormula {
value: ProcessedComputable<DecimalSource>
): InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula {
return new Formula({ variable: value }); return new Formula({ variable: value });
} }
@ -228,9 +224,7 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
public static step( public static step(
value: FormulaSource, value: FormulaSource,
start: Computable<DecimalSource>, start: Computable<DecimalSource>,
formulaModifier: ( formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula
) => GenericFormula
) { ) {
const lhsRef = ref<DecimalSource>(0); const lhsRef = ref<DecimalSource>(0);
const formula = formulaModifier(Formula.variable(lhsRef)); const formula = formulaModifier(Formula.variable(lhsRef));
@ -271,12 +265,8 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
public static if( public static if(
value: FormulaSource, value: FormulaSource,
condition: Computable<boolean>, condition: Computable<boolean>,
formulaModifier: ( formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula,
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula elseFormulaModifier?: (value: InvertibleIntegralFormula) => GenericFormula
) => GenericFormula,
elseFormulaModifier?: (
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula
) => GenericFormula
) { ) {
const lhsRef = ref<DecimalSource>(0); const lhsRef = ref<DecimalSource>(0);
const variable = Formula.variable(lhsRef); const variable = Formula.variable(lhsRef);
@ -319,12 +309,8 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
public static conditional( public static conditional(
value: FormulaSource, value: FormulaSource,
condition: Computable<boolean>, condition: Computable<boolean>,
formulaModifier: ( formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula,
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula elseFormulaModifier?: (value: InvertibleIntegralFormula) => GenericFormula
) => GenericFormula,
elseFormulaModifier?: (
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula
) => GenericFormula
) { ) {
return Formula.if(value, condition, formulaModifier, elseFormulaModifier); return Formula.if(value, condition, formulaModifier, elseFormulaModifier);
} }
@ -872,26 +858,20 @@ export abstract class InternalFormula<T extends [FormulaSource] | FormulaSource[
public step( public step(
start: Computable<DecimalSource>, start: Computable<DecimalSource>,
formulaModifier: ( formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula
) => GenericFormula
) { ) {
return Formula.step(this, start, formulaModifier); return Formula.step(this, start, formulaModifier);
} }
public if( public if(
condition: Computable<boolean>, condition: Computable<boolean>,
formulaModifier: ( formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula
) => GenericFormula
) { ) {
return Formula.if(this, condition, formulaModifier); return Formula.if(this, condition, formulaModifier);
} }
public conditional( public conditional(
condition: Computable<boolean>, condition: Computable<boolean>,
formulaModifier: ( formulaModifier: (value: InvertibleIntegralFormula) => GenericFormula
value: InvertibleFormula & IntegrableFormula & InvertibleIntegralFormula
) => GenericFormula
) { ) {
return Formula.if(this, condition, formulaModifier); return Formula.if(this, condition, formulaModifier);
} }

View file

@ -5,7 +5,7 @@ import {
setupPassiveGeneration setupPassiveGeneration
} from "features/conversion"; } from "features/conversion";
import { createResource, Resource } from "features/resources/resource"; import { createResource, Resource } from "features/resources/resource";
import { GenericFormula } from "game/formulas/types"; import { InvertibleIntegralFormula } from "game/formulas/types";
import { createLayer, GenericLayer } from "game/layers"; import { createLayer, GenericLayer } from "game/layers";
import Decimal from "util/bignum"; import Decimal from "util/bignum";
import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
@ -15,7 +15,7 @@ import "../utils";
describe("Creating conversion", () => { describe("Creating conversion", () => {
let baseResource: Resource; let baseResource: Resource;
let gainResource: Resource; let gainResource: Resource;
let formula: (x: GenericFormula) => GenericFormula; let formula: (x: InvertibleIntegralFormula) => InvertibleIntegralFormula;
beforeEach(() => { beforeEach(() => {
baseResource = createResource(ref(40)); baseResource = createResource(ref(40));
gainResource = createResource(ref(1)); gainResource = createResource(ref(1));
@ -449,7 +449,7 @@ describe("Creating conversion", () => {
describe("Passive generation", () => { describe("Passive generation", () => {
let baseResource: Resource; let baseResource: Resource;
let gainResource: Resource; let gainResource: Resource;
let formula: (x: GenericFormula) => GenericFormula; let formula: (x: InvertibleIntegralFormula) => InvertibleIntegralFormula;
let conversion: GenericConversion; let conversion: GenericConversion;
let layer: GenericLayer; let layer: GenericLayer;
beforeEach(() => { beforeEach(() => {