1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Apply lint rule @typescript-eslint/no-empty-object-type (#4679)

This commit is contained in:
Michael Telatynski
2025-02-04 13:41:32 +00:00
committed by GitHub
parent 72519a0eb4
commit ea34cce00a
20 changed files with 108 additions and 84 deletions

View File

@ -112,8 +112,13 @@ module.exports = {
"@typescript-eslint/ban-ts-comment": "off",
// We're okay with assertion errors when we ask for them
"@typescript-eslint/no-non-null-assertion": "off",
// We do this sometimes to brand interfaces
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-empty-object-type": [
"error",
{
// We do this sometimes to brand interfaces
allowInterfaces: "with-single-extends",
},
],
"quotes": "off",
// We use a `logger` intermediary module
@ -147,6 +152,7 @@ module.exports = {
// We don't need super strict typing in test utilities
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/no-empty-object-type": "off",
},
},
],

View File

@ -17,6 +17,7 @@ limitations under the License.
import {
ClientEvent,
ClientEventHandlerMap,
EmptyObject,
EventType,
GroupCall,
GroupCallIntent,
@ -466,7 +467,7 @@ export class MockCallMatrixClient extends TypedEventEmitter<EmittedEvents, Emitt
[roomId: string, eventType: EventType, content: any, statekey: string]
>();
public sendToDevice = jest.fn<
Promise<{}>,
Promise<EmptyObject>,
[eventType: string, contentMap: SendToDeviceContentMap, txnId?: string]
>();

View File

@ -33,6 +33,7 @@ import {
AccountDataEvents,
Device,
DeviceVerification,
EmptyObject,
encodeBase64,
HttpApiEvent,
HttpApiEventHandlerMap,
@ -2348,7 +2349,7 @@ class DummyAccountDataClient
}
}
public async setAccountData(eventType: string, content: any): Promise<{}> {
public async setAccountData(eventType: string, content: any): Promise<EmptyObject> {
this.storage.set(eventType, content);
this.emit(
ClientEvent.AccountData,

View File

@ -20,3 +20,5 @@ export type NonEmptyArray<T> = [T, ...T[]];
export type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
export type EmptyObject = Record<PropertyKey, never>;

View File

@ -38,7 +38,7 @@ import {
import { IGroupCallRoomMemberState, IGroupCallRoomState } from "../webrtc/groupCall.ts";
import { MSC3089EventContent } from "../models/MSC3089Branch.ts";
import { M_BEACON, M_BEACON_INFO, MBeaconEventContent, MBeaconInfoEventContent } from "./beacon.ts";
import { XOR } from "./common.ts";
import { EmptyObject } from "./common.ts";
import { ReactionEventContent, RoomMessageEventContent, StickerEventContent } from "./events.ts";
import {
MCallAnswer,
@ -337,7 +337,7 @@ export interface StateEvents {
[EventType.RoomJoinRules]: RoomJoinRulesEventContent;
[EventType.RoomMember]: RoomMemberEventContent;
// XXX: Spec says this event has 3 required fields but kicking such an invitation requires sending `{}`
[EventType.RoomThirdPartyInvite]: XOR<RoomThirdPartyInviteEventContent, {}>;
[EventType.RoomThirdPartyInvite]: RoomThirdPartyInviteEventContent | EmptyObject;
[EventType.RoomPowerLevels]: RoomPowerLevelsEventContent;
[EventType.RoomName]: RoomNameEventContent;
[EventType.RoomTopic]: RoomTopicEventContent;
@ -351,13 +351,13 @@ export interface StateEvents {
[EventType.SpaceChild]: SpaceChildEventContent;
[EventType.SpaceParent]: SpaceParentEventContent;
[EventType.PolicyRuleUser]: XOR<PolicyRuleEventContent, {}>;
[EventType.PolicyRuleRoom]: XOR<PolicyRuleEventContent, {}>;
[EventType.PolicyRuleServer]: XOR<PolicyRuleEventContent, {}>;
[EventType.PolicyRuleUser]: PolicyRuleEventContent | EmptyObject;
[EventType.PolicyRuleRoom]: PolicyRuleEventContent | EmptyObject;
[EventType.PolicyRuleServer]: PolicyRuleEventContent | EmptyObject;
// MSC3401
[EventType.GroupCallPrefix]: IGroupCallRoomState;
[EventType.GroupCallMemberPrefix]: XOR<IGroupCallRoomMemberState, XOR<SessionMembershipData, {}>>;
[EventType.GroupCallMemberPrefix]: IGroupCallRoomMemberState | SessionMembershipData | EmptyObject;
// MSC3089
[UNSTABLE_MSC3089_BRANCH.name]: MSC3089EventContent;
@ -372,7 +372,7 @@ export interface StateEvents {
export interface AccountDataEvents extends SecretStorageAccountDataEvents {
[EventType.PushRules]: IPushRules;
[EventType.Direct]: { [userId: string]: string[] };
[EventType.IgnoredUserList]: { [userId: string]: {} };
[EventType.IgnoredUserList]: { ignored_users: { [userId: string]: EmptyObject } };
"m.secret_storage.default_key": { key: string };
// Flag set by the rust SDK (Element X) and also used by us to mark that the user opted out of backup
// (I don't know why it's m.org.matrix...)

View File

@ -97,12 +97,12 @@ export type AnyRelation = TSNamespace<typeof REFERENCE_RELATION> | string;
/**
* An m.relates_to relationship
*/
export type RelatesToRelationship<R = never, C = never> = {
export type RelatesToRelationship<R = never> = {
"m.relates_to": {
// See https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887 for array syntax
rel_type: [R] extends [never] ? AnyRelation : TSNamespace<R>;
event_id: string;
} & DefaultNever<C, {}>;
};
};
/**

View File

@ -60,6 +60,7 @@ declare global {
};
}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface DummyInterfaceWeShouldntBeUsingThis {}
interface Navigator {

View File

@ -22,6 +22,7 @@ import {
RelatesToRelationship,
TSNamespace,
} from "./extensible_events.ts";
import { EmptyObject } from "./common.ts";
/**
* Identifier for a disclosed poll.
@ -109,7 +110,7 @@ export const M_POLL_END = new UnstableValue("m.poll.end", "org.matrix.msc3381.po
/**
* The event definition for an m.poll.end event (in content)
*/
export type PollEndEvent = EitherAnd<{ [M_POLL_END.name]: {} }, { [M_POLL_END.altName]: {} }>;
export type PollEndEvent = EitherAnd<{ [M_POLL_END.name]: EmptyObject }, { [M_POLL_END.altName]: EmptyObject }>;
/**
* The content for an m.poll.end event

View File

@ -249,6 +249,7 @@ import { Capabilities, ServerCapabilities } from "./serverCapabilities.ts";
import { sha256 } from "./digest.ts";
import { keyFromAuthData } from "./common-crypto/key-passphrase.ts";
import { discoverAndValidateOIDCIssuerWellKnown, OidcClientConfig, validateAuthMetadataAndKeys } from "./oidc/index.ts";
import { EmptyObject } from "./@types/common.ts";
export type Store = IStore;
@ -4251,7 +4252,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public setAccountData<K extends keyof AccountDataEvents>(
eventType: K,
content: AccountDataEvents[K] | Record<string, never>,
): Promise<{}> {
): Promise<EmptyObject> {
const path = utils.encodeUri("/user/$userId/account_data/$type", {
$userId: this.credentials.userId!,
$type: eventType,
@ -4338,8 +4339,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: an empty object
* @returns Rejects: with an error response.
*/
public setIgnoredUsers(userIds: string[]): Promise<{}> {
const content = { ignored_users: {} as Record<string, object> };
public setIgnoredUsers(userIds: string[]): Promise<EmptyObject> {
const content = { ignored_users: {} as Record<string, EmptyObject> };
userIds.forEach((u) => {
content.ignored_users[u] = {};
});
@ -4520,7 +4521,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object
* @returns Rejects: with an error response.
*/
public setRoomTag(roomId: string, tagName: string, metadata: ITagMetadata = {}): Promise<{}> {
public setRoomTag(roomId: string, tagName: string, metadata: ITagMetadata = {}): Promise<EmptyObject> {
const path = utils.encodeUri("/user/$userId/rooms/$roomId/tags/$tag", {
$userId: this.credentials.userId!,
$roomId: roomId,
@ -4534,7 +4535,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object
* @returns Rejects: with an error response.
*/
public deleteRoomTag(roomId: string, tagName: string): Promise<{}> {
public deleteRoomTag(roomId: string, tagName: string): Promise<EmptyObject> {
const path = utils.encodeUri("/user/$userId/rooms/$roomId/tags/$tag", {
$userId: this.credentials.userId!,
$roomId: roomId,
@ -4549,7 +4550,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object `{}`
* @returns Rejects: with an error response.
*/
public setRoomAccountData(roomId: string, eventType: string, content: Record<string, any>): Promise<{}> {
public setRoomAccountData(roomId: string, eventType: string, content: Record<string, any>): Promise<EmptyObject> {
const path = utils.encodeUri("/user/$userId/rooms/$roomId/account_data/$type", {
$userId: this.credentials.userId!,
$roomId: roomId,
@ -5449,7 +5450,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* Check progress on [MSC4140](https://github.com/matrix-org/matrix-spec-proposals/pull/4140) for more details.
*/
// eslint-disable-next-line
public async _unstable_updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<{}> {
public async _unstable_updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<EmptyObject> {
if (!(await this.doesServerSupportUnstableFeature(UNSTABLE_MSC4140_DELAYED_EVENTS))) {
throw Error("Server does not support the delayed events API");
}
@ -5480,7 +5481,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
receiptType: ReceiptType,
body?: Record<string, any>,
unthreaded = false,
): Promise<{}> {
): Promise<EmptyObject> {
if (this.isGuest()) {
return Promise.resolve({}); // guests cannot send receipts so don't bother.
}
@ -5496,7 +5497,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
const shouldAddThreadId = !unthreaded && this.supportsThreads();
const fullBody = shouldAddThreadId ? { ...body, thread_id: threadIdForReceipt(event) } : body;
const promise = this.http.authedRequest<{}>(Method.Post, path, undefined, fullBody || {});
const promise = this.http.authedRequest<EmptyObject>(Method.Post, path, undefined, fullBody || {});
const room = this.getRoom(event.getRoomId());
if (room && this.credentials.userId) {
@ -5516,7 +5517,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
event: MatrixEvent | null,
receiptType = ReceiptType.Read,
unthreaded = false,
): Promise<{} | undefined> {
): Promise<EmptyObject | undefined> {
if (!event) return;
const eventId = event.getId()!;
const room = this.getRoom(event.getRoomId());
@ -5546,7 +5547,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
rmEventId: string,
rrEvent?: MatrixEvent,
rpEvent?: MatrixEvent,
): Promise<{}> {
): Promise<EmptyObject> {
const room = this.getRoom(roomId);
if (room?.hasPendingEvent(rmEventId)) {
throw new Error(`Cannot set read marker to a pending event (${rmEventId})`);
@ -5627,7 +5628,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object `{}`
* @returns Rejects: with an error response.
*/
public sendTyping(roomId: string, isTyping: boolean, timeoutMs: number): Promise<{}> {
public sendTyping(roomId: string, isTyping: boolean, timeoutMs: number): Promise<EmptyObject> {
if (this.isGuest()) {
return Promise.resolve({}); // guests cannot send typing notifications so don't bother.
}
@ -5745,7 +5746,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public invite(roomId: string, userId: string, reason?: string): Promise<{}> {
public invite(roomId: string, userId: string, reason?: string): Promise<EmptyObject> {
return this.membershipChange(roomId, userId, KnownMembership.Invite, reason);
}
@ -5756,7 +5757,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public inviteByEmail(roomId: string, email: string): Promise<{}> {
public inviteByEmail(roomId: string, email: string): Promise<EmptyObject> {
return this.inviteByThreePid(roomId, "email", email);
}
@ -5768,7 +5769,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public async inviteByThreePid(roomId: string, medium: string, address: string): Promise<{}> {
public async inviteByThreePid(roomId: string, medium: string, address: string): Promise<EmptyObject> {
const path = utils.encodeUri("/rooms/$roomId/invite", { $roomId: roomId });
const identityServerUrl = this.getIdentityServerUrl(true);
@ -5800,7 +5801,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public leave(roomId: string): Promise<{}> {
public leave(roomId: string): Promise<EmptyObject> {
return this.membershipChange(roomId, undefined, KnownMembership.Leave);
}
@ -5858,7 +5859,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: TODO
* @returns Rejects: with an error response.
*/
public ban(roomId: string, userId: string, reason?: string): Promise<{}> {
public ban(roomId: string, userId: string, reason?: string): Promise<EmptyObject> {
return this.membershipChange(roomId, userId, KnownMembership.Ban, reason);
}
@ -5868,12 +5869,12 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public async forget(roomId: string, deleteRoom = true): Promise<{}> {
public async forget(roomId: string, deleteRoom = true): Promise<EmptyObject> {
// API returns an empty object
const path = utils.encodeUri("/rooms/$room_id/forget", {
$room_id: roomId,
});
const response = await this.http.authedRequest<{}>(Method.Post, path);
const response = await this.http.authedRequest<EmptyObject>(Method.Post, path);
if (deleteRoom) {
this.store.removeRoom(roomId);
this.emit(ClientEvent.DeleteRoom, roomId);
@ -5885,7 +5886,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: Object (currently empty)
* @returns Rejects: with an error response.
*/
public unban(roomId: string, userId: string): Promise<{}> {
public unban(roomId: string, userId: string): Promise<EmptyObject> {
// unbanning != set their state to leave: this used to be
// the case, but was then changed so that leaving was always
// a revoking of privilege, otherwise two people racing to
@ -5905,7 +5906,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public kick(roomId: string, userId: string, reason?: string): Promise<{}> {
public kick(roomId: string, userId: string, reason?: string): Promise<EmptyObject> {
const path = utils.encodeUri("/rooms/$roomId/kick", {
$roomId: roomId,
});
@ -5921,7 +5922,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
userId: string | undefined,
membership: Membership,
reason?: string,
): Promise<{}> {
): Promise<EmptyObject> {
// API returns an empty object
const path = utils.encodeUri("/rooms/$room_id/$membership", {
$room_id: roomId,
@ -5972,9 +5973,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Rejects: with an error response.
*/
// eslint-disable-next-line camelcase
public setProfileInfo(info: "avatar_url", data: { avatar_url: string }): Promise<{}>;
public setProfileInfo(info: "displayname", data: { displayname: string }): Promise<{}>;
public setProfileInfo(info: "avatar_url" | "displayname", data: object): Promise<{}> {
public setProfileInfo(info: "avatar_url", data: { avatar_url: string }): Promise<EmptyObject>;
public setProfileInfo(info: "displayname", data: { displayname: string }): Promise<EmptyObject>;
public setProfileInfo(info: "avatar_url" | "displayname", data: object): Promise<EmptyObject> {
const path = utils.encodeUri("/profile/$userId/$info", {
$userId: this.credentials.userId!,
$info: info,
@ -5986,7 +5987,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public async setDisplayName(name: string): Promise<{}> {
public async setDisplayName(name: string): Promise<EmptyObject> {
const prom = await this.setProfileInfo("displayname", { displayname: name });
// XXX: synthesise a profile update for ourselves because Synapse is broken and won't
const user = this.getUser(this.getUserId()!);
@ -6001,7 +6002,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: `{}` an empty object.
* @returns Rejects: with an error response.
*/
public async setAvatarUrl(url: string): Promise<{}> {
public async setAvatarUrl(url: string): Promise<EmptyObject> {
const prom = await this.setProfileInfo("avatar_url", { avatar_url: url });
// XXX: synthesise a profile update for ourselves because Synapse is broken and won't
const user = this.getUser(this.getUserId()!);
@ -8363,7 +8364,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @param stopClient - whether to stop the client before calling /logout to prevent invalid token errors.
* @returns Promise which resolves: On success, the empty object `{}`
*/
public async logout(stopClient = false): Promise<{}> {
public async logout(stopClient = false): Promise<EmptyObject> {
if (this.crypto?.backupManager?.getKeyBackupEnabled()) {
try {
while ((await this.crypto.backupManager.backupPendingKeys(200)) > 0);
@ -8421,7 +8422,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* or UIA auth data.
*/
public async requestLoginToken(auth?: AuthDict): Promise<UIAResponse<LoginTokenPostResponse>> {
const body: UIARequest<{}> = { auth };
const body: UIARequest<unknown> = { auth };
return this.http.authedRequest<UIAResponse<LoginTokenPostResponse>>(
Method.Post,
"/login/get_token",
@ -8662,7 +8663,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
rmEventId: string,
rrEventId?: string,
rpEventId?: string,
): Promise<{}> {
): Promise<EmptyObject> {
const path = utils.encodeUri("/rooms/$roomId/read_markers", {
$roomId: roomId,
});
@ -8737,7 +8738,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: an empty object `{}`
* @returns Rejects: with an error response.
*/
public createAlias(alias: string, roomId: string): Promise<{}> {
public createAlias(alias: string, roomId: string): Promise<EmptyObject> {
const path = utils.encodeUri("/directory/room/$alias", {
$alias: alias,
});
@ -8754,7 +8755,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: an empty object `{}`.
* @returns Rejects: with an error response.
*/
public deleteAlias(alias: string): Promise<{}> {
public deleteAlias(alias: string): Promise<EmptyObject> {
const path = utils.encodeUri("/directory/room/$alias", {
$alias: alias,
});
@ -8808,7 +8809,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object `{}`
* @returns Rejects: with an error response.
*/
public setRoomDirectoryVisibility(roomId: string, visibility: Visibility): Promise<{}> {
public setRoomDirectoryVisibility(roomId: string, visibility: Visibility): Promise<EmptyObject> {
const path = utils.encodeUri("/directory/list/room/$roomId", {
$roomId: roomId,
});
@ -9083,7 +9084,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object `{}`
* @returns Rejects: with an error response.
*/
public async addThreePidOnly(data: IAddThreePidOnlyBody): Promise<{}> {
public async addThreePidOnly(data: IAddThreePidOnlyBody): Promise<EmptyObject> {
const path = "/account/3pid/add";
return this.http.authedRequest(Method.Post, path, undefined, data);
}
@ -9099,7 +9100,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object `{}`
* @returns Rejects: with an error response.
*/
public async bindThreePid(data: IBindThreePidBody): Promise<{}> {
public async bindThreePid(data: IBindThreePidBody): Promise<EmptyObject> {
const path = "/account/3pid/bind";
return this.http.authedRequest(Method.Post, path, undefined, data);
}
@ -9153,7 +9154,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: to an empty object `{}`
* @returns Rejects: with an error response.
*/
public setPassword(authDict: AuthDict, newPassword: string, logoutDevices?: boolean): Promise<{}> {
public setPassword(authDict: AuthDict, newPassword: string, logoutDevices?: boolean): Promise<EmptyObject> {
const path = "/account/password";
const data = {
auth: authDict,
@ -9161,7 +9162,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
logout_devices: logoutDevices,
};
return this.http.authedRequest<{}>(Method.Post, path, undefined, data);
return this.http.authedRequest<EmptyObject>(Method.Post, path, undefined, data);
}
/**
@ -9195,7 +9196,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Rejects: with an error response.
*/
// eslint-disable-next-line camelcase
public setDeviceDetails(deviceId: string, body: { display_name: string }): Promise<{}> {
public setDeviceDetails(deviceId: string, body: { display_name: string }): Promise<EmptyObject> {
const path = utils.encodeUri("/devices/$device_id", {
$device_id: deviceId,
});
@ -9211,7 +9212,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: result object
* @returns Rejects: with an error response.
*/
public deleteDevice(deviceId: string, auth?: AuthDict): Promise<{}> {
public deleteDevice(deviceId: string, auth?: AuthDict): Promise<EmptyObject> {
const path = utils.encodeUri("/devices/$device_id", {
$device_id: deviceId,
});
@ -9233,7 +9234,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: result object
* @returns Rejects: with an error response.
*/
public deleteMultipleDevices(devices: string[], auth?: AuthDict): Promise<{}> {
public deleteMultipleDevices(devices: string[], auth?: AuthDict): Promise<EmptyObject> {
const body: Body = { devices };
if (auth) {
@ -9274,7 +9275,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: Empty json object on success
* @returns Rejects: with an error response.
*/
public setPusher(pusher: IPusherRequest): Promise<{}> {
public setPusher(pusher: IPusherRequest): Promise<EmptyObject> {
const path = "/pushers/set";
return this.http.authedRequest(Method.Post, path, undefined, pusher);
}
@ -9286,7 +9287,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: Empty json object on success
* @returns Rejects: with an error response.
*/
public removePusher(pushKey: string, appId: string): Promise<{}> {
public removePusher(pushKey: string, appId: string): Promise<EmptyObject> {
const path = "/pushers/set";
const body = {
pushkey: pushKey,
@ -9304,7 +9305,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public setLocalNotificationSettings(
deviceId: string,
notificationSettings: LocalNotificationSettings,
): Promise<{}> {
): Promise<EmptyObject> {
const key = `${LOCAL_NOTIFICATION_SETTINGS_PREFIX.name}.${deviceId}` as const;
return this.setAccountData(key, notificationSettings);
}
@ -9341,7 +9342,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
kind: PushRuleKind,
ruleId: Exclude<string, RuleId>,
body: Pick<IPushRule, "actions" | "conditions" | "pattern">,
): Promise<{}> {
): Promise<EmptyObject> {
// NB. Scope not uri encoded because devices need the '/'
const path = utils.encodeUri("/pushrules/" + scope + "/$kind/$ruleId", {
$kind: kind,
@ -9354,7 +9355,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Promise which resolves: an empty object `{}`
* @returns Rejects: with an error response.
*/
public deletePushRule(scope: string, kind: PushRuleKind, ruleId: Exclude<string, RuleId>): Promise<{}> {
public deletePushRule(scope: string, kind: PushRuleKind, ruleId: Exclude<string, RuleId>): Promise<EmptyObject> {
// NB. Scope not uri encoded because devices need the '/'
const path = utils.encodeUri("/pushrules/" + scope + "/$kind/$ruleId", {
$kind: kind,
@ -9373,7 +9374,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
kind: PushRuleKind,
ruleId: RuleId | string,
enabled: boolean,
): Promise<{}> {
): Promise<EmptyObject> {
const path = utils.encodeUri("/pushrules/" + scope + "/$kind/$ruleId/enabled", {
$kind: kind,
$ruleId: ruleId,
@ -9391,7 +9392,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
kind: PushRuleKind,
ruleId: RuleId | string,
actions: PushRuleAction[],
): Promise<{}> {
): Promise<EmptyObject> {
const path = utils.encodeUri("/pushrules/" + scope + "/$kind/$ruleId/actions", {
$kind: kind,
$ruleId: ruleId,
@ -9517,7 +9518,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
return this.http.authedRequest(Method.Get, "/keys/changes", qps);
}
public uploadDeviceSigningKeys(auth?: AuthDict, keys?: CrossSigningKeys): Promise<{}> {
public uploadDeviceSigningKeys(auth?: AuthDict, keys?: CrossSigningKeys): Promise<EmptyObject> {
// API returns empty object
const data = Object.assign({}, keys);
if (auth) Object.assign(data, { auth });
@ -9857,7 +9858,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
medium: string;
mxid: string;
}
| {}
| EmptyObject
> {
// Note: we're using the V2 API by calling this function, but our
// function contract requires a V1 response. We therefore have to
@ -9953,7 +9954,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* supplied.
* @returns Promise which resolves: to an empty object `{}`
*/
public sendToDevice(eventType: string, contentMap: SendToDeviceContentMap, txnId?: string): Promise<{}> {
public sendToDevice(eventType: string, contentMap: SendToDeviceContentMap, txnId?: string): Promise<EmptyObject> {
const path = utils.encodeUri("/sendToDevice/$eventType/$txnId", {
$eventType: eventType,
$txnId: txnId ? txnId : this.makeTxnId(),
@ -10047,7 +10048,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
baseUrl: string,
accessToken: string,
termsUrls: string[],
): Promise<{}> {
): Promise<EmptyObject> {
const url = this.termsUrlForService(serviceType, baseUrl);
const headers = {
Authorization: "Bearer " + accessToken,
@ -10070,7 +10071,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @param reason - The reason the content is being reported. May be blank.
* @returns Promise which resolves to an empty object if successful
*/
public reportEvent(roomId: string, eventId: string, score: number, reason: string): Promise<{}> {
public reportEvent(roomId: string, eventId: string, score: number, reason: string): Promise<EmptyObject> {
const path = utils.encodeUri("/rooms/$roomId/report/$eventId", {
$roomId: roomId,
$eventId: eventId,

View File

@ -18,6 +18,7 @@ import { CryptoEvent } from "./CryptoEvent.ts";
import { VerificationRequest } from "./verification.ts";
import { UserVerificationStatus } from "./index.ts";
import { RustBackupCryptoEventMap } from "../rust-crypto/backup.ts";
import { EmptyObject } from "../@types/common.ts";
/**
* A map of the {@link CryptoEvent} fired by the {@link CryptoApi} and their payloads.
@ -26,7 +27,7 @@ export type CryptoEventHandlerMap = {
[CryptoEvent.VerificationRequestReceived]: (request: VerificationRequest) => void;
[CryptoEvent.UserTrustStatusChanged]: (userId: string, userTrustLevel: UserVerificationStatus) => void;
[CryptoEvent.KeyBackupDecryptionKeyCached]: (version: string) => void;
[CryptoEvent.KeysChanged]: (data: {}) => void;
[CryptoEvent.KeysChanged]: (data: EmptyObject) => void;
[CryptoEvent.WillUpdateDevices]: (users: string[], initialFetch: boolean) => void;
[CryptoEvent.DevicesUpdated]: (users: string[], initialFetch: boolean) => void;
[CryptoEvent.LegacyCryptoStoreMigrationProgress]: (progress: number, total: number) => void;

View File

@ -26,6 +26,7 @@ import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
import { AccountDataClient, SecretStorageKeyDescription } from "../secret-storage.ts";
import { BootstrapCrossSigningOpts, CrossSigningKeyInfo } from "../crypto-api/index.ts";
import { AccountDataEvents } from "../@types/event.ts";
import { EmptyObject } from "../@types/common.ts";
interface ICrossSigningKeys {
authUpload: BootstrapCrossSigningOpts["authUploadDeviceSigningKeys"];
@ -267,7 +268,7 @@ class AccountDataClientAdapter
public setAccountData<K extends keyof AccountDataEvents>(
type: K,
content: AccountDataEvents[K] | Record<string, never>,
): Promise<{}> {
): Promise<EmptyObject> {
const event = new MatrixEvent({ type, content });
const lastEvent = this.values.get(type);
this.values.set(type, event);

View File

@ -22,6 +22,7 @@ import { IRoomKeyRequestBody, IRoomKeyRequestRecipient } from "./index.ts";
import { CryptoStore, OutgoingRoomKeyRequest } from "./store/base.ts";
import { EventType, ToDeviceMessageId } from "../@types/event.ts";
import { MapWithDefault } from "../utils.ts";
import { EmptyObject } from "../@types/common.ts";
/**
* Internal module. Management of outgoing room key requests.
@ -460,7 +461,7 @@ export class OutgoingRoomKeyRequestManager {
message: RequestMessage,
recipients: IRoomKeyRequestRecipient[],
txnId?: string,
): Promise<{}> {
): Promise<EmptyObject> {
const contentMap = new MapWithDefault<string, Map<string, Record<string, any>>>(() => new Map());
for (const recip of recipients) {
const userDeviceMap = contentMap.getOrCreate(recip.userId);

View File

@ -57,7 +57,7 @@ import { ToDeviceBatch, ToDevicePayload } from "./models/ToDeviceMessage.ts";
import { DeviceInfo } from "./crypto/deviceinfo.ts";
import { IOlmDevice } from "./crypto/algorithms/megolm.ts";
import { MapWithDefault, recursiveMapToObject } from "./utils.ts";
import { TypedEventEmitter } from "./matrix.ts";
import { EmptyObject, TypedEventEmitter } from "./matrix.ts";
interface IStateEventRequest {
eventType: string;
@ -431,15 +431,16 @@ export class RoomWidgetClient extends MatrixClient {
* @experimental This currently relies on an unstable MSC (MSC4140).
*/
// eslint-disable-next-line
public async _unstable_updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<{}> {
public async _unstable_updateDelayedEvent(delayId: string, action: UpdateDelayedEventAction): Promise<EmptyObject> {
if (!(await this.doesServerSupportUnstableFeature(UNSTABLE_MSC4140_DELAYED_EVENTS))) {
throw Error("Server does not support the delayed events API");
}
return await this.widgetApi.updateDelayedEvent(delayId, action);
await this.widgetApi.updateDelayedEvent(delayId, action);
return {};
}
public async sendToDevice(eventType: string, contentMap: SendToDeviceContentMap): Promise<{}> {
public async sendToDevice(eventType: string, contentMap: SendToDeviceContentMap): Promise<EmptyObject> {
await this.widgetApi.sendToDevice(eventType, false, recursiveMapToObject(contentMap));
return {};
}

View File

@ -68,7 +68,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
this.opts.idBaseUrl = url;
}
public idServerRequest<T extends {} = Record<string, unknown>>(
public idServerRequest<T extends object = Record<string, unknown>>(
method: Method,
path: string,
params: Record<string, string | string[]> | undefined,

View File

@ -134,6 +134,7 @@ export type AuthDict =
| RecaptchaDict
| EmailIdentityDict
| { type: Exclude<string, AuthType>; [key: string]: any }
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
| {};
export class NoAuthFlowFoundError extends Error {
@ -421,10 +422,12 @@ export class InteractiveAuth<T> {
// use the sessionid from the last request, if one is present.
let auth: AuthDict;
if ((this.data as IAuthData)?.session) {
auth = {
session: (this.data as IAuthData).session,
};
Object.assign(auth, authData);
auth = Object.assign(
{
session: (this.data as IAuthData).session,
},
authData,
);
} else {
auth = authData;
}

View File

@ -10,6 +10,7 @@ import { CallMembership, DEFAULT_EXPIRE_DURATION, SessionMembershipData } from "
import { Focus } from "./focus.ts";
import { isLivekitFocusActive } from "./LivekitFocus.ts";
import { MembershipConfig } from "./MatrixRTCSession.ts";
import { EmptyObject } from "../@types/common.ts";
/**
* This interface defines what a MembershipManager uses and exposes.
* This interface is what we use to write tests and allows to change the actual implementation
@ -203,7 +204,7 @@ export class LegacyMembershipManager implements IMembershipManager {
this.updateCallMembershipRunning = false;
}
};
private makeNewMembership(deviceId: string): SessionMembershipData | {} {
private makeNewMembership(deviceId: string): SessionMembershipData | EmptyObject {
// If we're joined, add our own
if (this.isJoined()) {
return this.makeMyMembership(deviceId);
@ -239,7 +240,7 @@ export class LegacyMembershipManager implements IMembershipManager {
const localDeviceId = this.client.getDeviceId();
if (!localUserId || !localDeviceId) throw new Error("User ID or device ID was null!");
let newContent: {} | SessionMembershipData = {};
let newContent: EmptyObject | SessionMembershipData = {};
// TODO: add back expiary logic to non-legacy events
// previously we checked here if the event is timed out and scheduled a check if not.
// maybe there is a better way.

View File

@ -35,6 +35,7 @@ import { FileType } from "../http-api/index.ts";
import { KnownMembership } from "../@types/membership.ts";
import { RoomPowerLevelsEventContent, SpaceChildEventContent } from "../@types/state_events.ts";
import type { EncryptedFile, FileContent } from "../@types/media.ts";
import { EmptyObject } from "../@types/common.ts";
/**
* The recommended defaults for a tree space's power levels. Note that this
@ -81,7 +82,7 @@ export enum TreePermissions {
declare module "../@types/media" {
interface FileContent {
[UNSTABLE_MSC3089_LEAF.name]?: {};
[UNSTABLE_MSC3089_LEAF.name]?: EmptyObject;
}
}

View File

@ -49,6 +49,7 @@ import { EventTimeline } from "./event-timeline.ts";
import { Membership } from "../@types/membership.ts";
import { DecryptionFailureCode } from "../crypto-api/index.ts";
import { RoomState } from "./room-state.ts";
import { EmptyObject } from "../@types/common.ts";
export { EventStatus } from "./event-status.ts";
@ -1376,7 +1377,7 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
*
* @returns The redaction event JSON, or an empty object
*/
public getRedactionEvent(): IEvent | {} | null {
public getRedactionEvent(): IEvent | EmptyObject | null {
if (!this.isRedacted()) return null;
if (this.clearEvent?.unsigned) {

View File

@ -29,6 +29,7 @@ import encryptAESSecretStorageItem from "./utils/encryptAESSecretStorageItem.ts"
import decryptAESSecretStorageItem from "./utils/decryptAESSecretStorageItem.ts";
import { AESEncryptedSecretStoragePayload } from "./@types/AESEncryptedSecretStoragePayload.ts";
import { AccountDataEvents, SecretStorageAccountDataEvents } from "./@types/event.ts";
import { EmptyObject } from "./@types/common.ts";
export const SECRET_STORAGE_ALGORITHM_V1_AES = "m.secret_storage.v1.aes-hmac-sha2";
@ -151,7 +152,7 @@ export interface AccountDataClient extends TypedEventEmitter<ClientEvent.Account
setAccountData: <K extends keyof AccountDataEvents>(
eventType: K,
content: AccountDataEvents[K] | Record<string, never>,
) => Promise<{}>;
) => Promise<EmptyObject>;
}
/**

View File

@ -265,7 +265,7 @@ export enum ExtensionState {
/**
* An interface that must be satisfied to register extensions
*/
export interface Extension<Req extends {}, Res extends {}> {
export interface Extension<Req extends object, Res extends object> {
/**
* The extension name to go under 'extensions' in the request body.
* @returns The JSON key.