diff --git a/src/server/api/stream/types.ts b/src/server/api/stream/types.ts index 72451628de..c58a627eb3 100644 --- a/src/server/api/stream/types.ts +++ b/src/server/api/stream/types.ts @@ -17,14 +17,6 @@ import { Signin } from '@/models/entities/signin'; import { Page } from '@/models/entities/page'; import { Packed } from '@/misc/schema'; -// 辞書(interface or type)から{ type, body }ユニオンを定義 -// https://stackoverflow.com/questions/49311989/can-i-infer-the-type-of-a-value-using-extends-keyof-type -type EventUnions = { [K in keyof T]: { type: K; body: T[K]; } }; -type EventUnionFromDictionary< - T extends object, - U = EventUnions -> = U[keyof U]; - //#region Stream type-body definitions export interface InternalStreamTypes { antennaCreated: Antenna; @@ -217,6 +209,15 @@ export interface AdminStreamTypes { } //#endregion +// 辞書(interface or type)から{ type, body }ユニオンを定義 +// https://stackoverflow.com/questions/49311989/can-i-infer-the-type-of-a-value-using-extends-keyof-type +// VS Codeの展開を防止するためにEvents型を定義 +type Events = { [K in keyof T]: { type: K; body: T[K]; } }; +type EventUnionFromDictionary< + T extends object, + U = Events +> = U[keyof U]; + // name/messages(spec) pairs dictionary export type StreamMessages = { internal: { @@ -287,11 +288,11 @@ export type StreamMessages = { // API event definitions // ストリームごとのEmitterの辞書を用意 -type EventsDictionary = { [x in keyof StreamMessages]: Emitter void }> }; +type EventEmitterDictionary = { [x in keyof StreamMessages]: Emitter void }> }; // 共用体型を交差型にする型 https://stackoverflow.com/questions/54938141/typescript-convert-union-to-intersection type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; -// Emitter辞書をストリームごとに共用体型にし、UnionToIntersectionで交差型にする -export type StreamEventEmitter = UnionToIntersection; +// Emitter辞書から共用体型を作り、UnionToIntersectionで交差型にする +export type StreamEventEmitter = UnionToIntersection; // { [y in name]: (e: spec) => void }をまとめてその交差型をEmitterにかけるとts(2590)にひっかかる // provide stream channels union