From 65ae5c1cfc2660a488f77ddc33c139daeb5ea7d5 Mon Sep 17 00:00:00 2001 From: ShadiestGoat Date: Sat, 20 Feb 2021 22:27:50 +0000 Subject: [PATCH 1/6] Adds enforcing --- index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4d4a6ee49a4..3d5232c3a78 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1188,8 +1188,7 @@ declare module 'mongoose' { ? (typeof String | 'string' | 'String') : (Function | string); - type SchemaDefinitionProperty = SchemaTypeOptions | - SchemaDefinitionWithBuiltInClass | + type SchemaDefinitionProperty = T extends string | number ? SchemaDefinitionWithBuiltInClass : SchemaTypeOptions | typeof SchemaType | Schema> | Schema>[] | From 73c04bade13e30d7be91f9af6c50b1792a62c0c3 Mon Sep 17 00:00:00 2001 From: ShadiestGoat Date: Sat, 20 Feb 2021 22:29:45 +0000 Subject: [PATCH 2/6] *style* --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 3d5232c3a78..20771547dec 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1188,7 +1188,8 @@ declare module 'mongoose' { ? (typeof String | 'string' | 'String') : (Function | string); - type SchemaDefinitionProperty = T extends string | number ? SchemaDefinitionWithBuiltInClass : SchemaTypeOptions | + type SchemaDefinitionProperty = T extends string | number ? SchemaDefinitionWithBuiltInClass : + SchemaTypeOptions | typeof SchemaType | Schema> | Schema>[] | From d1576a0de425ccfee771a60907eec600c420f00a Mon Sep 17 00:00:00 2001 From: ShadiestGoat Date: Sun, 21 Feb 2021 00:32:38 +0000 Subject: [PATCH 3/6] no whitespace --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 20771547dec..668a7826cf1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1188,7 +1188,7 @@ declare module 'mongoose' { ? (typeof String | 'string' | 'String') : (Function | string); - type SchemaDefinitionProperty = T extends string | number ? SchemaDefinitionWithBuiltInClass : + type SchemaDefinitionProperty = T extends string | number ? SchemaDefinitionWithBuiltInClass : SchemaTypeOptions | typeof SchemaType | Schema> | From 8a7d33eab4663fdba2292bbf678c73d674123262 Mon Sep 17 00:00:00 2001 From: ShadiestGoat <48590492+ShadiestGoat@users.noreply.github.com> Date: Sun, 21 Feb 2021 01:55:30 +0000 Subject: [PATCH 4/6] Silly ol' me forgot about the function type aha --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 668a7826cf1..58cd9517a2a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1188,7 +1188,7 @@ declare module 'mongoose' { ? (typeof String | 'string' | 'String') : (Function | string); - type SchemaDefinitionProperty = T extends string | number ? SchemaDefinitionWithBuiltInClass : + type SchemaDefinitionProperty = T extends string | number | Function ? SchemaDefinitionWithBuiltInClass : SchemaTypeOptions | typeof SchemaType | Schema> | From e85e478ba888bebb9a30a88acf89809dc05843c9 Mon Sep 17 00:00:00 2001 From: ShadiestGoat <48590492+ShadiestGoat@users.noreply.github.com> Date: Mon, 22 Feb 2021 01:45:12 +0000 Subject: [PATCH 5/6] SchemaTypeOptions now works! I forgot to add this before I guess. This way, if T is a string/number/function, then it shows it as well. If it is another type, it also shows it (which is why it isn't any). --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 58cd9517a2a..6bd1ef37fbd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1188,7 +1188,8 @@ declare module 'mongoose' { ? (typeof String | 'string' | 'String') : (Function | string); - type SchemaDefinitionProperty = T extends string | number | Function ? SchemaDefinitionWithBuiltInClass : + type SchemaDefinitionProperty = type SchemaDefinitionProperty = T extends string | number | Function ? + SchemaDefinitionWithBuiltInClass | SchemaTypeOptions : SchemaTypeOptions | typeof SchemaType | Schema> | From f26939b961952ba4807cbfead1c005d80c5f7809 Mon Sep 17 00:00:00 2001 From: ShadiestGoat Date: Mon, 22 Feb 2021 01:55:14 +0000 Subject: [PATCH 6/6] enforcing onto SchemaTypeOptions --- index.d.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 668a7826cf1..b951f5e1937 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1182,13 +1182,14 @@ declare module 'mongoose' { virtualpath(name: string): VirtualType | null; } - type SchemaDefinitionWithBuiltInClass = T extends number + type SchemaDefinitionWithBuiltInClass = T extends number ? (typeof Number | 'number' | 'Number') : T extends string ? (typeof String | 'string' | 'String') : (Function | string); - type SchemaDefinitionProperty = T extends string | number ? SchemaDefinitionWithBuiltInClass : + type SchemaDefinitionProperty = T extends string | number | Function + ? (SchemaDefinitionWithBuiltInClass | SchemaTypeOptions) : SchemaTypeOptions | typeof SchemaType | Schema> | @@ -1365,7 +1366,7 @@ declare module 'mongoose' { } interface SchemaTypeOptions { - type?: T | SchemaDefinitionWithBuiltInClass; + type?: T extends string | number | Function ? SchemaDefinitionWithBuiltInClass : T; /** Defines a virtual with the given name that gets/sets this path. */ alias?: string;