You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way we model Gateway packets right now isn't wrong:
export interface GatewayMessage {
op: OPCode
d?: any
s?: number
t?: GatewayMessageType
}
…but, we could take advantage of TS to model them in a more correct fashion. s and t are virtually guaranteed to be non-null if op == OPCode.DISPATCH, so something this could be better:
realizes that the data (d) of a packet should really be unknown, not any. But, since it's the primary encapsulated content of a Gateway packet, so it makes sense to parameterize over it as a generic instead
We can also make more union variants for each OPCode type, and furthermore for each eventType too, probably. This would eliminate a lot of the type annotations from business logic, make it viable to enable strict in tsconfig.json, and give us stronger typing guarantees (meaning, less bugs).
The text was updated successfully, but these errors were encountered:
…but, we could take advantage of TS to model them in a more correct fashion. s and t are virtually guaranteed to be non-null if op == OPCode.DISPATCH, so something this could be better:
realizes that the data (d) of a packet should really be unknown, not any. But, since it's the primary encapsulated content of a Gateway packet, so it makes sense to parameterize over it as a generic instead
We can also make more union variants for each OPCode type, and furthermore for each eventType too, probably. This would eliminate a lot of the type annotations from business logic, make it viable to enable strict in tsconfig.json, and give us stronger typing guarantees (meaning, less bugs).
(Copied from GH)
The way we model Gateway packets right now isn't wrong:
…but, we could take advantage of TS to model them in a more correct fashion.
s
andt
are virtually guaranteed to be non-null
ifop == OPCode.DISPATCH
, so something this could be better:This also:
d
) of a packet should really beunknown
, notany
. But, since it's the primary encapsulated content of a Gateway packet, so it makes sense to parameterize over it as a generic insteadWe can also make more union variants for each
OPCode
type, and furthermore for eacheventType
too, probably. This would eliminate a lot of the type annotations from business logic, make it viable to enablestrict
intsconfig.json
, and give us stronger typing guarantees (meaning, less bugs).The text was updated successfully, but these errors were encountered: