[Re] refactor(misskey-js): 警告をすべて解決 (#14277)
* chore(misskey-js): Unchanged files with check annotationsで紛らわしい部分の警告を抑制 ロジック面は後で直す * dummy change to see if the feature do not report them (to be reverted after the check) * refactor: 型合わせ * refactor: fix warnings fromc22dd6358b
* lint * 型合わせ * キャスト * pnpm build-misskey-js-with-types * Revert "dummy change to see if the feature do not report them (to be reverted after the check)" This reverts commit67072e3ca6
. * eliminate reversiGame any * move reversiGame types * lint * Update packages/misskey-js/src/streaming.ts Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> * Update acct.ts * run api extractor * re-run api extractor --------- Co-authored-by: Kisaragi Marine <kisaragi.effective@gmail.com> Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,7 @@ export function urlQuery(obj: Record<string, string | number | boolean | undefin
|
||||
.join('&');
|
||||
}
|
||||
|
||||
type AnyOf<T extends Record<any, any>> = T[keyof T];
|
||||
type AnyOf<T extends Record<PropertyKey, unknown>> = T[keyof T];
|
||||
|
||||
type StreamEvents = {
|
||||
_connected_: void;
|
||||
@@ -25,6 +25,7 @@ type StreamEvents = {
|
||||
/**
|
||||
* Misskey stream connection
|
||||
*/
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default class Stream extends EventEmitter<StreamEvents> {
|
||||
private stream: _ReconnectingWebsocket.default;
|
||||
public state: 'initializing' | 'reconnecting' | 'connected' = 'initializing';
|
||||
@@ -34,7 +35,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
|
||||
private idCounter = 0;
|
||||
|
||||
constructor(origin: string, user: { token: string; } | null, options?: {
|
||||
WebSocket?: any;
|
||||
WebSocket?: WebSocket;
|
||||
}) {
|
||||
super();
|
||||
|
||||
@@ -51,6 +52,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
|
||||
this.send = this.send.bind(this);
|
||||
this.close = this.close.bind(this);
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
options = options ?? { };
|
||||
|
||||
const query = urlQuery({
|
||||
@@ -91,8 +93,8 @@ export default class Stream extends EventEmitter<StreamEvents> {
|
||||
this.sharedConnectionPools.push(pool);
|
||||
}
|
||||
|
||||
const connection = new SharedConnection(this, channel, pool, name);
|
||||
this.sharedConnections.push(connection);
|
||||
const connection = new SharedConnection<Channels[C]>(this, channel, pool, name);
|
||||
this.sharedConnections.push(connection as unknown as SharedConnection);
|
||||
return connection;
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ export default class Stream extends EventEmitter<StreamEvents> {
|
||||
|
||||
private connectToChannel<C extends keyof Channels>(channel: C, params: Channels[C]['params']): NonSharedConnection<Channels[C]> {
|
||||
const connection = new NonSharedConnection(this, channel, this.genId(), params);
|
||||
this.nonSharedConnections.push(connection);
|
||||
this.nonSharedConnections.push(connection as unknown as NonSharedConnection);
|
||||
return connection;
|
||||
}
|
||||
|
||||
@@ -174,9 +176,9 @@ export default class Stream extends EventEmitter<StreamEvents> {
|
||||
* ! ストリーム上のやり取りはすべてJSONで行われます !
|
||||
*/
|
||||
public send(typeOrPayload: string): void
|
||||
public send(typeOrPayload: string, payload: any): void
|
||||
public send(typeOrPayload: Record<string, any> | any[]): void
|
||||
public send(typeOrPayload: string | Record<string, any> | any[], payload?: any): void {
|
||||
public send(typeOrPayload: string, payload: unknown): void
|
||||
public send(typeOrPayload: Record<string, unknown> | unknown[]): void
|
||||
public send(typeOrPayload: string | Record<string, unknown> | unknown[], payload?: unknown): void {
|
||||
if (typeof typeOrPayload === 'string') {
|
||||
this.stream.send(JSON.stringify({
|
||||
type: typeOrPayload,
|
||||
@@ -211,7 +213,7 @@ class Pool {
|
||||
public id: string;
|
||||
protected stream: Stream;
|
||||
public users = 0;
|
||||
private disposeTimerId: any;
|
||||
private disposeTimerId: ReturnType<typeof setTimeout> | null = null;
|
||||
private isConnected = false;
|
||||
|
||||
constructor(stream: Stream, channel: string, id: string) {
|
||||
@@ -275,7 +277,7 @@ class Pool {
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class Connection<Channel extends AnyOf<Channels> = any> extends EventEmitter<Channel['events']> {
|
||||
export abstract class Connection<Channel extends AnyOf<Channels> = AnyOf<Channels>> extends EventEmitter<Channel['events']> {
|
||||
public channel: string;
|
||||
protected stream: Stream;
|
||||
public abstract id: string;
|
||||
@@ -309,7 +311,7 @@ export abstract class Connection<Channel extends AnyOf<Channels> = any> extends
|
||||
public abstract dispose(): void;
|
||||
}
|
||||
|
||||
class SharedConnection<Channel extends AnyOf<Channels> = any> extends Connection<Channel> {
|
||||
class SharedConnection<Channel extends AnyOf<Channels> = AnyOf<Channels>> extends Connection<Channel> {
|
||||
private pool: Pool;
|
||||
|
||||
public get id(): string {
|
||||
@@ -328,11 +330,11 @@ class SharedConnection<Channel extends AnyOf<Channels> = any> extends Connection
|
||||
public dispose(): void {
|
||||
this.pool.dec();
|
||||
this.removeAllListeners();
|
||||
this.stream.removeSharedConnection(this);
|
||||
this.stream.removeSharedConnection(this as unknown as SharedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
class NonSharedConnection<Channel extends AnyOf<Channels> = any> extends Connection<Channel> {
|
||||
class NonSharedConnection<Channel extends AnyOf<Channels> = AnyOf<Channels>> extends Connection<Channel> {
|
||||
public id: string;
|
||||
protected params: Channel['params'];
|
||||
|
||||
@@ -359,6 +361,6 @@ class NonSharedConnection<Channel extends AnyOf<Channels> = any> extends Connect
|
||||
public dispose(): void {
|
||||
this.removeAllListeners();
|
||||
this.stream.send('disconnect', { id: this.id });
|
||||
this.stream.disconnectToChannel(this);
|
||||
this.stream.disconnectToChannel(this as unknown as NonSharedConnection);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user