improve types
This commit is contained in:
@@ -5,6 +5,8 @@ import { ApiError } from './error';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { AccessToken } from '../../models/entities/access-token';
|
||||
|
||||
type NonOptional<T> = T extends undefined ? never : T;
|
||||
|
||||
type SimpleUserInfo = {
|
||||
id: ILocalUser['id'];
|
||||
host: ILocalUser['host'];
|
||||
@@ -17,11 +19,12 @@ type SimpleUserInfo = {
|
||||
isSilenced: ILocalUser['isSilenced'];
|
||||
};
|
||||
|
||||
// TODO: defaultが設定されている場合はその型も考慮する
|
||||
type Params<T extends IEndpointMeta> = {
|
||||
[P in keyof T['params']]: NonNullable<T['params']>[P]['transform'] extends Function
|
||||
? ReturnType<NonNullable<T['params']>[P]['transform']>
|
||||
: ReturnType<NonNullable<T['params']>[P]['validator']['get']>[0];
|
||||
: NonNullable<T['params']>[P]['default'] extends null | number | string
|
||||
? NonOptional<ReturnType<NonNullable<T['params']>[P]['validator']['get']>[0]>
|
||||
: ReturnType<NonNullable<T['params']>[P]['validator']['get']>[0];
|
||||
};
|
||||
|
||||
export type Response = Record<string, any> | void;
|
||||
|
Reference in New Issue
Block a user