Skip to content

Commit

Permalink
test: declare instead of instantiating collection in ts test
Browse files Browse the repository at this point in the history
  • Loading branch information
dariakp committed Dec 14, 2022
1 parent 3121fc5 commit 46cbd8d
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions test/types/schema_helpers.test-d.ts
@@ -1,7 +1,7 @@
import { Document, ObjectId } from 'bson';
import { expectAssignable, expectError, expectNotType, expectType } from 'tsd';

import { Collection, Db } from '../../src';
import type { Collection } from '../../src';
import type {
EnhancedOmit,
InferIdType,
Expand Down Expand Up @@ -64,9 +64,9 @@ interface SchemaWithIdInterface {
_id: ObjectId;
a: number;
}
declare const typeTestCollection: Collection<OptionalId<SchemaWithIdType>>;
declare const interfaceTestCollection: Collection<OptionalId<SchemaWithIdInterface>>;

const typeTestCollection = new Collection<OptionalId<SchemaWithIdType>>({} as Db, 'test');
const interfaceTestCollection = new Collection<OptionalId<SchemaWithIdInterface>>({} as Db, 'test');
expectAssignable<SchemaWithIdType | null>(await typeTestCollection.findOne());
expectAssignable<SchemaWithIdInterface | null>(await interfaceTestCollection.findOne());
expectAssignable<SchemaWithIdType>((await typeTestCollection.find().toArray())[0]);
Expand Down Expand Up @@ -99,14 +99,9 @@ interface SchemaWithIdNumberInterface {
_id: number;
a: number;
}
const typeNumberTestCollection = new Collection<OptionalId<SchemaWithIdNumberType>>(
{} as Db,
'test'
);
const interfaceNumberTestCollection = new Collection<OptionalId<SchemaWithIdNumberInterface>>(
{} as Db,
'test'
);
declare const typeNumberTestCollection: Collection<OptionalId<SchemaWithIdNumberType>>;
declare const interfaceNumberTestCollection: Collection<OptionalId<SchemaWithIdNumberInterface>>;

expectAssignable<SchemaWithIdNumberType | null>(await typeNumberTestCollection.findOne());
expectAssignable<SchemaWithIdNumberInterface | null>(await interfaceNumberTestCollection.findOne());
expectAssignable<SchemaWithIdNumberType>((await typeNumberTestCollection.find().toArray())[0]);
Expand Down

0 comments on commit 46cbd8d

Please sign in to comment.