@@ -136,6 +136,7 @@ import {
136136 UpdateDelayedEventAction ,
137137} from "./@types/requests.ts" ;
138138import {
139+ AccountDataEvents ,
139140 EventType ,
140141 LOCAL_NOTIFICATION_SETTINGS_PREFIX ,
141142 MSC3912_RELATION_BASED_REDACTIONS_PROP ,
@@ -232,6 +233,7 @@ import {
232233import { DeviceInfoMap } from "./crypto/DeviceList.ts" ;
233234import {
234235 AddSecretStorageKeyOpts ,
236+ SecretStorageKey ,
235237 SecretStorageKeyDescription ,
236238 ServerSideSecretStorage ,
237239 ServerSideSecretStorageImpl ,
@@ -3070,7 +3072,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
30703072 *
30713073 * @deprecated Use {@link MatrixClient#secretStorage} and {@link SecretStorage.ServerSideSecretStorage#isStored}.
30723074 */
3073- public isSecretStored ( name : string ) : Promise < Record < string , SecretStorageKeyDescription > | null > {
3075+ public isSecretStored ( name : SecretStorageKey ) : Promise < Record < string , SecretStorageKeyDescription > | null > {
30743076 return this . secretStorage . isStored ( name ) ;
30753077 }
30763078
@@ -4236,7 +4238,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
42364238 * @returns Promise which resolves: an empty object
42374239 * @returns Rejects: with an error response.
42384240 */
4239- public setAccountData ( eventType : EventType | string , content : IContent ) : Promise < { } > {
4241+ public setAccountData < K extends keyof AccountDataEvents > (
4242+ eventType : K ,
4243+ content : AccountDataEvents [ K ] | Record < string , never > ,
4244+ ) : Promise < { } > {
42404245 const path = utils . encodeUri ( "/user/$userId/account_data/$type" , {
42414246 $userId : this . credentials . userId ! ,
42424247 $type : eventType ,
@@ -4251,7 +4256,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
42514256 * @param eventType - The event type
42524257 * @returns The contents of the given account data event
42534258 */
4254- public getAccountData ( eventType : string ) : MatrixEvent | undefined {
4259+ public getAccountData < K extends keyof AccountDataEvents > ( eventType : K ) : MatrixEvent | undefined {
42554260 return this . store . getAccountData ( eventType ) ;
42564261 }
42574262
@@ -4263,15 +4268,17 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
42634268 * @returns Promise which resolves: The contents of the given account data event.
42644269 * @returns Rejects: with an error response.
42654270 */
4266- public async getAccountDataFromServer < T extends { [ k : string ] : any } > ( eventType : string ) : Promise < T | null > {
4271+ public async getAccountDataFromServer < K extends keyof AccountDataEvents > (
4272+ eventType : K ,
4273+ ) : Promise < AccountDataEvents [ K ] | null > {
42674274 if ( this . isInitialSyncComplete ( ) ) {
42684275 const event = this . store . getAccountData ( eventType ) ;
42694276 if ( ! event ) {
42704277 return null ;
42714278 }
42724279 // The network version below returns just the content, so this branch
42734280 // does the same to match.
4274- return event . getContent < T > ( ) ;
4281+ return event . getContent < AccountDataEvents [ K ] > ( ) ;
42754282 }
42764283 const path = utils . encodeUri ( "/user/$userId/account_data/$type" , {
42774284 $userId : this . credentials . userId ! ,
@@ -4287,7 +4294,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
42874294 }
42884295 }
42894296
4290- public async deleteAccountData ( eventType : string ) : Promise < void > {
4297+ public async deleteAccountData ( eventType : keyof AccountDataEvents ) : Promise < void > {
42914298 const msc3391DeleteAccountDataServerSupport = this . canSupport . get ( Feature . AccountDataDeletion ) ;
42924299 // if deletion is not supported overwrite with empty content
42934300 if ( msc3391DeleteAccountDataServerSupport === ServerSupport . Unsupported ) {
@@ -4310,7 +4317,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
43104317 * @returns The array of users that are ignored (empty if none)
43114318 */
43124319 public getIgnoredUsers ( ) : string [ ] {
4313- const event = this . getAccountData ( "m.ignored_user_list" ) ;
4320+ const event = this . getAccountData ( EventType . IgnoredUserList ) ;
43144321 if ( ! event ?. getContent ( ) [ "ignored_users" ] ) return [ ] ;
43154322 return Object . keys ( event . getContent ( ) [ "ignored_users" ] ) ;
43164323 }
@@ -4326,7 +4333,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
43264333 userIds . forEach ( ( u ) => {
43274334 content . ignored_users [ u ] = { } ;
43284335 } ) ;
4329- return this . setAccountData ( "m.ignored_user_list" , content ) ;
4336+ return this . setAccountData ( EventType . IgnoredUserList , content ) ;
43304337 }
43314338
43324339 /**
@@ -9264,7 +9271,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
92649271 deviceId : string ,
92659272 notificationSettings : LocalNotificationSettings ,
92669273 ) : Promise < { } > {
9267- const key = `${ LOCAL_NOTIFICATION_SETTINGS_PREFIX . name } .${ deviceId } ` ;
9274+ const key = `${ LOCAL_NOTIFICATION_SETTINGS_PREFIX . name } .${ deviceId } ` as const ;
92689275 return this . setAccountData ( key , notificationSettings ) ;
92699276 }
92709277
0 commit comments