Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MISC: Add generic type as returned type for action and checking #1748

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Bladeburner/Actions/Action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Bladeburner } from "../Bladeburner";
import type { Person } from "../../PersonObjects/Person";
import type { Availability, SuccessChanceParams } from "../Types";
import type { SuccessChanceParams } from "../Types";
import type { Availability } from "../../types";
import type { Skills as PersonSkills } from "../../PersonObjects/Skills";

import { addOffset } from "../../utils/helpers/addOffset";
Expand Down
3 changes: 2 additions & 1 deletion src/Bladeburner/Actions/BlackOperation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Bladeburner } from "../Bladeburner";
import type { ActionIdFor, Availability } from "../Types";
import type { ActionIdFor } from "../Types";
import type { Availability } from "../../types";

import { BladeburnerActionType, BladeburnerBlackOpName } from "@enums";
import { ActionClass, ActionParams } from "./Action";
Expand Down
2 changes: 1 addition & 1 deletion src/Bladeburner/Actions/LevelableAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Bladeburner } from "../Bladeburner";
import type { IReviverValue } from "../../utils/JSONReviver";
import type { Availability } from "../Types";
import type { Availability } from "../../types";

import { ActionClass, ActionParams } from "./Action";
import { getRandomIntInclusive } from "../../utils/helpers/getRandomIntInclusive";
Expand Down
3 changes: 2 additions & 1 deletion src/Bladeburner/Actions/Operation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Person } from "../../PersonObjects/Person";
import type { BlackOperation } from "./BlackOperation";
import type { Bladeburner } from "../Bladeburner";
import type { ActionIdFor, Availability, SuccessChanceParams } from "../Types";
import type { ActionIdFor, SuccessChanceParams } from "../Types";
import type { Availability } from "../../types";

import { BladeburnerActionType, BladeburnerMultName, BladeburnerOperationName } from "@enums";
import { BladeburnerConstants } from "../data/Constants";
Expand Down
3 changes: 2 additions & 1 deletion src/Bladeburner/Bladeburner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PromisePair } from "../Types/Promises";
import type { BlackOperation, Contract, GeneralAction, Operation } from "./Actions";
import type { Action, ActionIdFor, ActionIdentifier, Attempt } from "./Types";
import type { Action, ActionIdFor, ActionIdentifier } from "./Types";
import type { Attempt } from "../types";
import type { Person } from "../PersonObjects/Person";
import type { Skills as PersonSkills } from "../PersonObjects/Skills";

Expand Down
2 changes: 1 addition & 1 deletion src/Bladeburner/Skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BladeburnerMultName, BladeburnerSkillName } from "@enums";

import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { Bladeburner } from "./Bladeburner";
import { Availability } from "./Types";
import type { Availability } from "../types";
import { PositiveInteger, PositiveNumber, isPositiveInteger } from "../types";
import { PartialRecord, getRecordEntries } from "../Types/Record";

Expand Down
8 changes: 0 additions & 8 deletions src/Bladeburner/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ export interface SuccessChanceParams {
est: boolean;
}

type AvailabilitySuccess<T extends object> = { available: true } & T;
type AvailabilityFailure = { available?: undefined; error: string };
export type Availability<T extends object = object> = AvailabilitySuccess<T> | AvailabilityFailure;

type AttemptSuccess<T extends object> = { success: true; message?: string } & T;
type AttemptFailure = { success?: undefined; message: string };
export type Attempt<T extends object = object> = AttemptSuccess<T> | AttemptFailure;

export type Action = Contract | Operation | BlackOperation | GeneralAction;
export type ActionIdFor<ActionType extends Action> = Pick<ActionType, "type" | "name">;

Expand Down
14 changes: 12 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ export type Member<T> = T extends (infer arrayMember)[] ? arrayMember : T[keyof
//** Get the keys of an object where the values match a given type */
export type TypedKeys<Obj, T> = { [K in keyof Obj]-?: Obj[K] extends T ? K : never }[keyof Obj];

/** Status object for functions that return a boolean indicating success/failure
* and an optional message */
/**
* Status object for functions that return a boolean indicating success/failure
* and an optional message
*/
export interface IReturnStatus {
res: boolean;
msg?: string;
}

type AvailabilitySuccess<T extends object> = { available: true } & T;
type AvailabilityFailure = { available?: undefined; error: string };
catloversg marked this conversation as resolved.
Show resolved Hide resolved
export type Availability<T extends object = object> = AvailabilitySuccess<T> | AvailabilityFailure;

type AttemptSuccess<T extends object> = { success: true; message?: string } & T;
catloversg marked this conversation as resolved.
Show resolved Hide resolved
type AttemptFailure = { success?: undefined; message: string };
export type Attempt<T extends object = object> = AttemptSuccess<T> | AttemptFailure;

/** Defines the minimum and maximum values for a range.
* It is up to the consumer if these values are inclusive or exclusive.
* It is up to the implementor to ensure max > min. */
Expand Down