Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions source/arroost/components/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<key>} operation
*/
static applyOperation(operation) {
const tunnelFunction = TUNNELS[operation.type]
// @ts-expect-error: freaks out
tunnelFunction(operation)
}

Expand Down
1 change: 1 addition & 0 deletions source/arroost/entities/arrows/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion source/arroost/entities/arrows/reality.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 23 additions & 11 deletions source/nogan/declare.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,43 @@ declare type Behave<T extends Pulse> = ({
peak: SuccessPeak & { pulse: T }
}) => Peak

declare type BehaviourMap = {
[key in PulseType]: Behave<Extract<Pulse, { type: key }>>
declare type PulseMap<key extends PulseType = PulseType> = {
[P in key]: { type: P } & Omit<Extract<Pulse, { type: P }>, "type">
}[key]

declare type BehaviourMap<key extends PulseType = PulseType> = {
[P in key]: Behave<PulseMap<P>>
}

//===========//
// Operation //
//===========//
// Based on: https://github.com/microsoft/TypeScript/pull/47109
declare type Operation = ReportOperation | InstructionOperation
declare type Operate<T extends Operation> = (nogan: Nogan, operation: T) => Operation[]
declare type OperationMap = {
[key in OperationType]: Operate<Extract<Operation, { type: key }>>
declare type OperationMap<key extends OperationType = OperationType> = {
[P in key]: { type: P } & Omit<Extract<Operation, { type: P }>, "type">
}[key]

declare type Operate<key extends OperationType> = (nogan: Nogan, operation: OperationMap<key>) => Operation[]
declare type OperateMap<key extends OperationType = OperationType> = {
[P in key]: Operate<P>
}

declare type TunnelFunction<T extends Operation> = (operation: T) => void
declare type TunnelMap = {
[key in OperationType]: TunnelFunction<Extract<Operation, { type: key }>>
declare type TunnelFunction<key extends OperationType = OperationType> = (operation: OperationMap<key>) => void
declare type TunnelMap<key extends OperationType = OperationType> = {
[P in key]: TunnelFunction<P>
}

//======//
// 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
}

//=======//
Expand Down
12 changes: 5 additions & 7 deletions source/nogan/nogan.js
Original file line number Diff line number Diff line change
Expand Up @@ -1603,13 +1603,12 @@ const getBehavedPeak = ({ nogan, source, target, previous, peak }) => {
}

/**
* @template {Pulse} T
* @param {T} pulse
* @returns {Behave<T>}
* @template {PulseType} T
* @param {PulseMap<T>} pulse
* @returns {Behave<PulseMap<T>>}
*/
export const getBehave = (pulse) => {
const behave = BEHAVIOURS[pulse.type]
// @ts-expect-error
return behave
}

Expand Down Expand Up @@ -1721,12 +1720,11 @@ export const applyOperations = (nogan, { operations }) => {
}

/**
* @template {Operation} T
* @param {T} operation
* @template {OperationType} T
* @param {OperationMap<T>} operation
* @returns {Operate<T>}
*/
export const getOperate = (operation) => {
const operate = OPERATIONS[operation.type]
// @ts-expect-error
return operate
}
2 changes: 1 addition & 1 deletion source/nogan/operate.js
Original file line number Diff line number Diff line change
@@ -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 }) {
Expand Down