1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Improve types (#3175)

* Improve types

* Add test
This commit is contained in:
Michael Telatynski
2023-02-22 17:39:37 +00:00
committed by GitHub
parent 21cc9c3d8a
commit d70ffdbc02
4 changed files with 34 additions and 22 deletions

View File

@@ -4130,7 +4130,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public setPowerLevel(
roomId: string,
userId: string | string[],
powerLevel: number,
powerLevel: number | undefined,
event: MatrixEvent | null,
): Promise<ISendEventResponse> {
let content = {
@@ -4141,13 +4141,16 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
// existing client state with a failed power level change
content = utils.deepCopy(event.getContent());
}
if (Array.isArray(userId)) {
for (const user of userId) {
const users = Array.isArray(userId) ? userId : [userId];
for (const user of users) {
if (powerLevel == null) {
delete content.users[user];
} else {
content.users[user] = powerLevel;
}
} else {
content.users[userId] = powerLevel;
}
const path = utils.encodeUri("/rooms/$roomId/state/m.room.power_levels", {
$roomId: roomId,
});
@@ -8746,18 +8749,19 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
email: string,
clientSecret: string,
sendAttempt: number,
nextLink: string,
nextLink?: string,
identityAccessToken?: string,
): Promise<any> {
// TODO: Types
const params = {
): Promise<IRequestTokenResponse> {
const params: Record<string, string> = {
client_secret: clientSecret,
email: email,
send_attempt: sendAttempt?.toString(),
next_link: nextLink,
};
if (nextLink) {
params.next_link = nextLink;
}
return this.http.idServerRequest(
return this.http.idServerRequest<IRequestTokenResponse>(
Method.Post,
"/validate/email/requestToken",
params,
@@ -8788,7 +8792,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @param identityAccessToken - The `access_token` field of the Identity
* Server `/account/register` response (see {@link registerWithIdentityServer}).
*
* @returns Promise which resolves: TODO
* @returns Promise which resolves to an object with a sid string
* @returns Rejects: with an error response.
* @throws Error if no identity server is set
*/
@@ -8797,19 +8801,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
phoneNumber: string,
clientSecret: string,
sendAttempt: number,
nextLink: string,
nextLink?: string,
identityAccessToken?: string,
): Promise<any> {
// TODO: Types
const params = {
): Promise<IRequestMsisdnTokenResponse> {
const params: Record<string, string> = {
client_secret: clientSecret,
country: phoneCountry,
phone_number: phoneNumber,
send_attempt: sendAttempt?.toString(),
next_link: nextLink,
};
if (nextLink) {
params.next_link = nextLink;
}
return this.http.idServerRequest(
return this.http.idServerRequest<IRequestMsisdnTokenResponse>(
Method.Post,
"/validate/msisdn/requestToken",
params,