Commit 505ed718 authored by nanahira's avatar nanahira

use PartialDeep

parent 8a2cd12a
import { Context } from 'koishi'; import { Context } from 'koishi';
import { InjectConfig } from './decorators'; import { InjectConfig } from './decorators';
export class BasePlugin<C, PC = Partial<C>> { export type PartialDeep<T> = T extends
| string
| number
| bigint
| boolean
| null
| undefined
| symbol
| Date
? T | undefined
: // Arrays, Sets and Maps and their readonly counterparts have their items made
// deeply partial, but their own instances are left untouched
T extends Array<infer ArrayType>
? Array<PartialDeep<ArrayType>>
: T extends ReadonlyArray<infer ArrayType>
? ReadonlyArray<ArrayType>
: T extends Set<infer SetType>
? Set<PartialDeep<SetType>>
: T extends ReadonlySet<infer SetType>
? ReadonlySet<SetType>
: T extends Map<infer KeyType, infer ValueType>
? Map<PartialDeep<KeyType>, PartialDeep<ValueType>>
: T extends ReadonlyMap<infer KeyType, infer ValueType>
? ReadonlyMap<PartialDeep<KeyType>, PartialDeep<ValueType>>
: // ...and finally, all other objects.
{
[K in keyof T]?: PartialDeep<T[K]>;
};
export class BasePlugin<C, PC = PartialDeep<C>> {
constructor(protected ctx: Context, config: PC) {} constructor(protected ctx: Context, config: PC) {}
@InjectConfig() @InjectConfig()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment