mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Fix type checking on Request and Event types
When defining a generic type where a type argument is never used as a part of the type itself, TypeScript will consider two instances of the generic type with different values for the type to be the same. This caused the handle method to accept any handler for any Request/Event, ignoring the event/request type completely. Fix by specifying the constructor to return the intersection of the type itself and the Request/Event type.
This commit is contained in:
1 parent
f23e442c4c
commit
fc6e9d0002
2 files changed
+6
-6
No files matched your search
@@ -11,8 +11,8 @@ import type { User } from "../users";
|
||||
import type { AddressType, JSONDeserialisable, MessageRoutable, MessageRequest, MessageEvent } from "../data";
|
||||
|
||||
export interface Request<Req, Res> {
|
||||
constructor: Partial<JSONDeserialisable<Request<Req, Res>>> & {
|
||||
new (...args: any): Request<Req, Res>,
|
||||
constructor: Partial<JSONDeserialisable<Req & Request<Req, Res>>> & {
|
||||
new (...args: any): Req & Request<Req, Res>,
|
||||
name: string,
|
||||
type: "request";
|
||||
src: AddressType | readonly AddressType[];
|
||||
@@ -25,8 +25,8 @@ export interface Request<Req, Res> {
|
||||
export type RequestClass<Req, Res> = Request<Req, Res>["constructor"];
|
||||
|
||||
export interface Event<T> {
|
||||
constructor: Partial<JSONDeserialisable<Event<T>>> & {
|
||||
new (...args: any): Event<T>,
|
||||
constructor: Partial<JSONDeserialisable<T & Event<T>>> & {
|
||||
new (...args: any): T & Event<T>,
|
||||
name: string,
|
||||
type: "event";
|
||||
src: AddressType | readonly AddressType[];
|
||||
|
||||
Reference in new issue
Block a user