diff --git a/source/arroost/components/tunnel.js b/source/arroost/components/tunnel.js index 9808823..9311478 100644 --- a/source/arroost/components/tunnel.js +++ b/source/arroost/components/tunnel.js @@ -66,11 +66,12 @@ export class Tunnel extends Component { } /** - * @param {Operation} operation + * Typing based on: https://github.com/microsoft/TypeScript/pull/47109 + * @template {OperationType} key + * @param {OperationMap} operation */ static applyOperation(operation) { const tunnelFunction = TUNNELS[operation.type] - // @ts-expect-error: freaks out tunnelFunction(operation) } diff --git a/source/arroost/entities/arrows/connection.js b/source/arroost/entities/arrows/connection.js index 1760cbe..8dff9f1 100644 --- a/source/arroost/entities/arrows/connection.js +++ b/source/arroost/entities/arrows/connection.js @@ -170,6 +170,7 @@ export class ArrowOfConnection extends Entity { const entity = target.entity const dummyWire = new ArrowOfTime({ // @ts-expect-error - Don't know why it isn't figuring out its type here. + // See: https://github.com/microsoft/TypeScript/issues/50651#issuecomment-1476795579 source: sourceEntity, target: entity, timing: ArrowOfConnection.timing, diff --git a/source/arroost/entities/arrows/reality.js b/source/arroost/entities/arrows/reality.js index 3d24b74..fce2660 100644 --- a/source/arroost/entities/arrows/reality.js +++ b/source/arroost/entities/arrows/reality.js @@ -97,7 +97,7 @@ export class ArrowOfReality extends Entity { const operations = [] for (const key in fire) { if (fire[key] === null) continue - // @ts-expect-error: cant be fucked to type Fire correctly + // @ts-expect-error: `Fire` is typed correctly, but `fire` may theoretically be a subtype with additional keys operations.push(...fireCell(shared.nogan, { id, colour: key })) } return operations diff --git a/source/nogan/declare.d.ts b/source/nogan/declare.d.ts index b3426c6..76ec396 100644 --- a/source/nogan/declare.d.ts +++ b/source/nogan/declare.d.ts @@ -95,31 +95,43 @@ declare type Behave = ({ peak: SuccessPeak & { pulse: T } }) => Peak -declare type BehaviourMap = { - [key in PulseType]: Behave> +declare type PulseMap = { + [P in key]: { type: P } & Omit, "type"> +}[key] + +declare type BehaviourMap = { + [P in key]: Behave> } //===========// // Operation // //===========// +// Based on: https://github.com/microsoft/TypeScript/pull/47109 declare type Operation = ReportOperation | InstructionOperation -declare type Operate = (nogan: Nogan, operation: T) => Operation[] -declare type OperationMap = { - [key in OperationType]: Operate> +declare type OperationMap = { + [P in key]: { type: P } & Omit, "type"> +}[key] + +declare type Operate = (nogan: Nogan, operation: OperationMap) => Operation[] +declare type OperateMap = { + [P in key]: Operate

} -declare type TunnelFunction = (operation: T) => void -declare type TunnelMap = { - [key in OperationType]: TunnelFunction> +declare type TunnelFunction = (operation: OperationMap) => void +declare type TunnelMap = { + [P in key]: TunnelFunction

} //======// // Fire // //======// +// declare type Fire = { +// red: Pulse | null +// green: Pulse | null +// blue: Pulse | null +// } declare type Fire = { - red: Pulse | null - green: Pulse | null - blue: Pulse | null + [key in PulseColour]: Pulse | null } //=======// diff --git a/source/nogan/nogan.js b/source/nogan/nogan.js index 75ebbe3..23d43d1 100644 --- a/source/nogan/nogan.js +++ b/source/nogan/nogan.js @@ -1603,13 +1603,12 @@ const getBehavedPeak = ({ nogan, source, target, previous, peak }) => { } /** - * @template {Pulse} T - * @param {T} pulse - * @returns {Behave} + * @template {PulseType} T + * @param {PulseMap} pulse + * @returns {Behave>} */ export const getBehave = (pulse) => { const behave = BEHAVIOURS[pulse.type] - // @ts-expect-error return behave } @@ -1721,12 +1720,11 @@ export const applyOperations = (nogan, { operations }) => { } /** - * @template {Operation} T - * @param {T} operation + * @template {OperationType} T + * @param {OperationMap} operation * @returns {Operate} */ export const getOperate = (operation) => { const operate = OPERATIONS[operation.type] - // @ts-expect-error return operate } diff --git a/source/nogan/operate.js b/source/nogan/operate.js index 1d2857f..dcf2a51 100644 --- a/source/nogan/operate.js +++ b/source/nogan/operate.js @@ -1,6 +1,6 @@ import { getCell, getWire, modifyCell, modifyWire, unfireCell } from "./nogan.js" -/** @type {OperationMap} */ +/** @type {OperateMap} */ export const OPERATIONS = { /** Modify a cell */ modifyCell(nogan, { id, template }) {