UNPKG

960 BTypeScriptView Raw
1declare module 'mongoose' {
2 type VirtualPathFunctions<DocType = {}, PathValueType = unknown, TInstanceMethods = {}> = {
3 get?: TVirtualPathFN<DocType, PathValueType, TInstanceMethods, PathValueType>;
4 set?: TVirtualPathFN<DocType, PathValueType, TInstanceMethods, void>;
5 options?: VirtualTypeOptions<HydratedDocument<DocType, TInstanceMethods>, DocType>;
6 };
7
8 type TVirtualPathFN<DocType = {}, PathType = unknown, TInstanceMethods = {}, TReturn = unknown> =
9 <T = HydratedDocument<DocType, TInstanceMethods>>(this: Document<any, any, DocType> & DocType, value: PathType, virtual: VirtualType<T>, doc: Document<any, any, DocType> & DocType) => TReturn;
10
11 type SchemaOptionsVirtualsPropertyType<DocType = any, VirtualPaths = Record<any, unknown>, TInstanceMethods = {}> = {
12 [K in keyof VirtualPaths]: VirtualPathFunctions<IsItRecordAndNotAny<DocType> extends true ? DocType : any, VirtualPaths[K], TInstanceMethods>
13 };
14}