Use mapped types around account data events (#28752)
* Use mapped types around account data events --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import type {
|
||||
Upload,
|
||||
StateEvents,
|
||||
TimelineEvents,
|
||||
AccountDataEvents,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import type { RoomMessageEventContent } from "matrix-js-sdk/src/types";
|
||||
import { Credentials } from "../plugins/homeserver";
|
||||
@@ -439,11 +440,14 @@ export class Client {
|
||||
* @param type The type of account data to set
|
||||
* @param content The content to set
|
||||
*/
|
||||
public async setAccountData(type: string, content: IContent): Promise<void> {
|
||||
public async setAccountData<T extends keyof AccountDataEvents>(
|
||||
type: T,
|
||||
content: AccountDataEvents[T],
|
||||
): Promise<void> {
|
||||
const client = await this.prepareClient();
|
||||
return client.evaluate(
|
||||
async (client, { type, content }) => {
|
||||
await client.setAccountData(type, content);
|
||||
await client.setAccountData(type as T, content as AccountDataEvents[T]);
|
||||
},
|
||||
{ type, content },
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user