Skip to content

Commit

Permalink
Delete InferDocumentType helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad0-0ahmad committed Jul 19, 2022
1 parent 3e9ea71 commit 4741531
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
8 changes: 4 additions & 4 deletions test/types/virtuals.test.ts
@@ -1,4 +1,4 @@
import { Document, Model, Schema, model, InferSchemaType, InferDocumentType, FlatRecord } from 'mongoose';
import { Document, Model, Schema, model, InferSchemaType, FlatRecord, ObtainSchemaGeneric } from 'mongoose';
import { expectType } from 'tsd';

interface IPerson {
Expand Down Expand Up @@ -90,7 +90,7 @@ function gh11543() {
function autoTypedVirtuals() {
type AutoTypedSchemaType = InferSchemaType<typeof testSchema>;
type VirtualsType = { domain: string };
type InferredDocType = InferDocumentType<typeof testSchema>;
type InferredDocType = FlatRecord<AutoTypedSchemaType & ObtainSchemaGeneric<typeof testSchema, 'TVirtuals'>>;

const testSchema = new Schema({
email: {
Expand Down Expand Up @@ -118,5 +118,5 @@ function autoTypedVirtuals() {
const doc = new TestModel();
expectType<string>(doc.domain);

expectType<FlatRecord<AutoTypedSchemaType &VirtualsType >>({} as InferredDocType);
}
expectType<FlatRecord<AutoTypedSchemaType & VirtualsType >>({} as InferredDocType);
}
12 changes: 0 additions & 12 deletions types/inferschematype.d.ts
Expand Up @@ -40,18 +40,6 @@ declare module 'mongoose' {
*/
type InferSchemaType<SchemaType> = ObtainSchemaGeneric<SchemaType, 'DocType'>;

/**
* @summary Obtains document plain doc type from Schema instance.
* @description Exactly like {@link InferSchemaType}, but it add virtual paths.
* @param {SchemaType} SchemaType A generic of schema type instance.
* @example
* const userSchema = new Schema({userName:String});
* type UserType = InferDocumentType<typeof userSchema>;
* // result
* type UserType = {userName?: string}
*/
type InferDocumentType<SchemaType> = FlatRecord<InferSchemaType<SchemaType> & ObtainSchemaGeneric<SchemaType, 'TVirtuals'>>;

/**
* @summary Obtains schema Generic type by using generic alias.
* @param {TSchema} TSchema A generic of schema type instance.
Expand Down

0 comments on commit 4741531

Please sign in to comment.