Skip to content

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

source/arroost/components/tunnel.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ export class Tunnel extends Component {
6666
}
6767

6868
/**
69-
* @param {Operation} operation
69+
* Typing based on: https://github.com/microsoft/TypeScript/pull/47109
70+
* @template {OperationType} key
71+
* @param {OperationMap<key>} operation
7072
*/
7173
static applyOperation(operation) {
7274
const tunnelFunction = TUNNELS[operation.type]
73-
// @ts-expect-error: freaks out
7475
tunnelFunction(operation)
7576
}
7677

source/arroost/entities/arrows/connection.js

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class ArrowOfConnection extends Entity {
170170
const entity = target.entity
171171
const dummyWire = new ArrowOfTime({
172172
// @ts-expect-error - Don't know why it isn't figuring out its type here.
173+
// See: https://github.com/microsoft/TypeScript/issues/50651#issuecomment-1476795579
173174
source: sourceEntity,
174175
target: entity,
175176
timing: ArrowOfConnection.timing,

source/arroost/entities/arrows/reality.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class ArrowOfReality extends Entity {
9797
const operations = []
9898
for (const key in fire) {
9999
if (fire[key] === null) continue
100-
// @ts-expect-error: cant be fucked to type Fire correctly
100+
// @ts-expect-error: `Fire` is typed correctly, but `fire` may theoretically be a subtype with additional keys
101101
operations.push(...fireCell(shared.nogan, { id, colour: key }))
102102
}
103103
return operations

source/nogan/declare.d.ts

+23-11
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,43 @@ declare type Behave<T extends Pulse> = ({
9595
peak: SuccessPeak & { pulse: T }
9696
}) => Peak
9797

98-
declare type BehaviourMap = {
99-
[key in PulseType]: Behave<Extract<Pulse, { type: key }>>
98+
declare type PulseMap<key extends PulseType = PulseType> = {
99+
[P in key]: { type: P } & Omit<Extract<Pulse, { type: P }>, "type">
100+
}[key]
101+
102+
declare type BehaviourMap<key extends PulseType = PulseType> = {
103+
[P in key]: Behave<PulseMap<P>>
100104
}
101105

102106
//===========//
103107
// Operation //
104108
//===========//
109+
// Based on: https://github.com/microsoft/TypeScript/pull/47109
105110
declare type Operation = ReportOperation | InstructionOperation
106-
declare type Operate<T extends Operation> = (nogan: Nogan, operation: T) => Operation[]
107-
declare type OperationMap = {
108-
[key in OperationType]: Operate<Extract<Operation, { type: key }>>
111+
declare type OperationMap<key extends OperationType = OperationType> = {
112+
[P in key]: { type: P } & Omit<Extract<Operation, { type: P }>, "type">
113+
}[key]
114+
115+
declare type Operate<key extends OperationType> = (nogan: Nogan, operation: OperationMap<key>) => Operation[]
116+
declare type OperateMap<key extends OperationType = OperationType> = {
117+
[P in key]: Operate<P>
109118
}
110119

111-
declare type TunnelFunction<T extends Operation> = (operation: T) => void
112-
declare type TunnelMap = {
113-
[key in OperationType]: TunnelFunction<Extract<Operation, { type: key }>>
120+
declare type TunnelFunction<key extends OperationType = OperationType> = (operation: OperationMap<key>) => void
121+
declare type TunnelMap<key extends OperationType = OperationType> = {
122+
[P in key]: TunnelFunction<P>
114123
}
115124

116125
//======//
117126
// Fire //
118127
//======//
128+
// declare type Fire = {
129+
// red: Pulse | null
130+
// green: Pulse | null
131+
// blue: Pulse | null
132+
// }
119133
declare type Fire = {
120-
red: Pulse | null
121-
green: Pulse | null
122-
blue: Pulse | null
134+
[key in PulseColour]: Pulse | null
123135
}
124136

125137
//=======//

source/nogan/nogan.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1603,13 +1603,12 @@ const getBehavedPeak = ({ nogan, source, target, previous, peak }) => {
16031603
}
16041604

16051605
/**
1606-
* @template {Pulse} T
1607-
* @param {T} pulse
1608-
* @returns {Behave<T>}
1606+
* @template {PulseType} T
1607+
* @param {PulseMap<T>} pulse
1608+
* @returns {Behave<PulseMap<T>>}
16091609
*/
16101610
export const getBehave = (pulse) => {
16111611
const behave = BEHAVIOURS[pulse.type]
1612-
// @ts-expect-error
16131612
return behave
16141613
}
16151614

@@ -1721,12 +1720,11 @@ export const applyOperations = (nogan, { operations }) => {
17211720
}
17221721

17231722
/**
1724-
* @template {Operation} T
1725-
* @param {T} operation
1723+
* @template {OperationType} T
1724+
* @param {OperationMap<T>} operation
17261725
* @returns {Operate<T>}
17271726
*/
17281727
export const getOperate = (operation) => {
17291728
const operate = OPERATIONS[operation.type]
1730-
// @ts-expect-error
17311729
return operate
17321730
}

source/nogan/operate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCell, getWire, modifyCell, modifyWire, unfireCell } from "./nogan.js"
22

3-
/** @type {OperationMap} */
3+
/** @type {OperateMap} */
44
export const OPERATIONS = {
55
/** Modify a cell */
66
modifyCell(nogan, { id, template }) {

0 commit comments

Comments
 (0)