Skip to content

Commit 2638c9a

Browse files
committed
WIP: clean up most remaining tests re: #14954
1 parent 279c5eb commit 2638c9a

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

test/types/schema.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ export function autoTypedSchema() {
473473
decimal1: Schema.Types.Decimal128,
474474
decimal2: 'Decimal128',
475475
decimal3: 'decimal128'
476-
});
476+
} as const);
477477

478478
type InferredTestSchemaType = InferSchemaType<typeof TestSchema>;
479479

@@ -508,12 +508,12 @@ export function autoTypedSchema() {
508508
}),
509509
favoritDrink: {
510510
type: String,
511-
enum: ['Coffee', 'Tea']
511+
enum: ['Coffee', 'Tea'] as const
512512
},
513513
favoritColorMode: {
514514
type: String,
515515
enum: {
516-
values: ['dark', 'light'],
516+
values: ['dark', 'light'] as const,
517517
message: '{VALUE} is not supported'
518518
},
519519
required: true
@@ -597,8 +597,8 @@ function encryptionType() {
597597
expectError(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'newFakeEncryptionType' }));
598598
expectError(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 1 }));
599599

600-
expectType<Schema>(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'queryableEncryption' }));
601-
expectType<Schema>(new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'csfle' }));
600+
const schema1 = new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'queryableEncryption' });
601+
const schema2 = new Schema<unknown>({ name: { type: String, encrypt: { keyId } } }, { encryptionType: 'csfle' });
602602
}
603603

604604
function gh11828() {
@@ -707,7 +707,7 @@ function gh12030() {
707707
}>({} as B);
708708

709709
expectType<{
710-
users: Types.DocumentArray<{
710+
users: Array<{
711711
username?: string | null
712712
}>;
713713
}>({} as InferSchemaType<typeof Schema1>);
@@ -728,7 +728,7 @@ function gh12030() {
728728
});
729729

730730
expectType<{
731-
users: Types.DocumentArray<{
731+
users: Array<{
732732
credit: number;
733733
username?: string | null;
734734
}>;
@@ -780,7 +780,7 @@ function pluginOptions() {
780780
}
781781

782782
const schema = new Schema({});
783-
expectType<Schema<any, any>>(schema.plugin(pluginFunction)); // test that chaining would be possible
783+
schema.plugin(pluginFunction); // test that chaining would be possible
784784

785785
// could not add strict tests that the parameters are inferred correctly, because i dont know how this would be done in tsd
786786

@@ -1028,7 +1028,7 @@ function gh12869() {
10281028
const dbExample = new Schema(
10291029
{
10301030
active: { type: String, enum: ['foo', 'bar'], required: true }
1031-
}
1031+
} as const
10321032
);
10331033

10341034
type Example = InferSchemaType<typeof dbExample>;
@@ -1056,7 +1056,7 @@ function gh12882() {
10561056
}],
10571057
required: true
10581058
}
1059-
});
1059+
} as const);
10601060
type tArrNum = InferSchemaType<typeof arrNum>;
10611061
expectType<{
10621062
fooArray: number[]
@@ -1079,7 +1079,7 @@ function gh12882() {
10791079
});
10801080
type tArrType = InferSchemaType<typeof arrType>;
10811081
expectType<{
1082-
fooArray: Types.DocumentArray<{
1082+
fooArray: Array<{
10831083
type: string;
10841084
foo: number;
10851085
}>
@@ -1130,7 +1130,7 @@ function gh12882() {
11301130
});
11311131
type rTArrType = InferSchemaType<typeof rArrType>;
11321132
expectType<{
1133-
fooArray: Types.DocumentArray<{
1133+
fooArray: Array<{
11341134
type: string;
11351135
foo: number;
11361136
}>

types/inferrawdoctype.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
PathWithTypePropertyBaseType,
77
PathEnumOrString
88
} from './inferschematype';
9+
import { UUID } from 'mongodb';
910

1011
declare module 'mongoose' {
1112
export type InferRawDocType<
@@ -105,7 +106,7 @@ declare module 'mongoose' {
105106
IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
106107
IfEquals<PathValueType, BigInt> extends true ? bigint :
107108
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
108-
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
109+
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? UUID :
109110
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
110111
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolveRawPathType<Options['of']>> :
111112
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolveRawPathType<Options['of']>> :

types/inferschematype.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ type IsPathDefaultUndefined<PathType> = PathType extends { default: undefined }
108108
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
109109
*/
110110
type IsPathRequired<P, TypeKey extends string = DefaultTypeKey> =
111-
P extends { required: true | (string | boolean)[] | { isRequired: true } } | ArrayConstructor | any[]
111+
P extends { required: true | (boolean | string)[] | { isRequired: true } } | ArrayConstructor | any[] | ReadonlyArray<any>
112112
? true
113113
: P extends { required: boolean }
114114
? P extends { required: false }
115115
? false
116116
: true
117-
: P extends (Record<TypeKey, ArrayConstructor | any[]>)
117+
: P extends (Record<TypeKey, ArrayConstructor | any[] | ReadonlyArray<any>>)
118118
? IsPathDefaultUndefined<P> extends true
119119
? false
120120
: true

0 commit comments

Comments
 (0)