feat: `lib.announce` type hints.

This commit is contained in:
Rintim 2024-03-17 20:24:32 +08:00
parent 7dbd42f1b4
commit 0a2e2a7cba
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
2 changed files with 59 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import { NonameAnnounceType } from "./interface.d.ts"
export interface IAnnounceSubscriber { export interface IAnnounceSubscriber {
subscribe(name: string): void; subscribe(name: string): void;
unsubscribe(name: string): void; unsubscribe(name: string): void;
@ -21,7 +23,7 @@ export class Announce {
* @param name - * @param name -
* @param values - * @param values -
*/ */
publish<T>(name: string, values: T): T publish<Type extends NonameAnnounceType, Name extends keyof Type>(name: Name, values: Parameters<Type[Name]>[0]): Parameters<Type[Name]>[0]
/** /**
* *
@ -33,7 +35,7 @@ export class Announce {
* @param name - * @param name -
* @param method - * @param method -
*/ */
subscribe<T>(name: string, method: (values: T) => void): (values: T) => void subscribe<Type extends NonameAnnounceType, Name extends keyof Type>(name: Name, method: Type[Name]): Type[Name]
/** /**
* *
@ -43,7 +45,7 @@ export class Announce {
* @param name - * @param name -
* @param method - * @param method -
*/ */
unsubscribe<T>(name: string, method: (values: T) => void): (values: T) => void unsubscribe<Type extends NonameAnnounceType, Name extends keyof Type>(name: Name, method: Type[Name]): Type[Name]
} }
export class AnnounceSubscriber<T> implements IAnnounceSubscriber { export class AnnounceSubscriber<T> implements IAnnounceSubscriber {

54
noname/library/announce/interface.d.ts vendored Normal file
View File

@ -0,0 +1,54 @@
export interface NonameAnnounceType {
// Apperaence 外观区域
// 用于关于无名杀外观方面的通知
// Apperaence.Theme 无名杀主题区域
/**
*
*
* @param values -
*/
"Noname.Apperaence.Theme.onChanging": AnnounceFunction<string>
/**
*
*
* @param values -
*/
"Noname.Apperaence.Theme.onChanged": AnnounceFunction<string>
/**
*
*
* @param values -
*/
"Noname.Apperaence.Theme.onChangeFinished": AnnounceFunction<string>
// Game 游戏区域
// 包含游戏对局下的通知
// Game.Event 事件区域
/**
*
*
* @param values -
*/
"Noname.Game.Event.GameStart": AnnounceFunction<{}>
// Init 初始化区域
// 用于关于初始化方面的通知
// Init.Extension 扩展初始化区域
/**
*
*
* @param values -
*/
"Noname.Init.Extension.onLoad": AnnounceFunction<string>
}
export type AnnounceFunction<T> = (values: T) => void