refactor: hide parameterized locale strings from type data in ts access

This commit is contained in:
Acid Chicken (硫酸鶏) 2024-01-19 01:09:06 +09:00
parent 5d7e6913d3
commit 4ec15002bf
No known key found for this signature in database
GPG Key ID: 3E87B98A3F6BAB99
1 changed files with 5 additions and 1 deletions

View File

@ -25,6 +25,10 @@ type ParametersOf<T extends ILocale, TKey extends FlattenKeys<T, ParameterizedSt
: never
: never;
type Ts<T extends ILocale> = {
readonly [K in keyof T as T[K] extends ParameterizedString<string> ? never : K]: T[K] extends ILocale ? Ts<T[K]> : string;
};
export class I18n<T extends ILocale> {
constructor(private locale: T) {
//#region BIND
@ -32,7 +36,7 @@ export class I18n<T extends ILocale> {
//#endregion
}
public get ts(): T {
public get ts(): Ts<T> {
if (_DEV_) {
class Handler<TTarget extends object> implements ProxyHandler<TTarget> {
get(target: TTarget, p: string | symbol): unknown {