Skip to content

Commit

Permalink
test: add example of explicit embedded usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Oct 6, 2022
1 parent 42c9507 commit 18e267c
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions test/types/community/collection/recursive-types.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import { expectAssignable, expectError, expectNotAssignable } from 'tsd';
import { expectAssignable, expectError, expectNotAssignable, expectNotType } from 'tsd';

import type { Collection, Filter, UpdateFilter } from '../../../../src';

/**
* mutually recursive types are not supported and will not get type safety
*/
interface Author {
books: Book[];
favoritePublication: Book;
name: string;
favoritePublication: Book;
}

interface Book {
author: Author;
title: string;
published: Date;
author: Author;
}

declare const mutuallyRecursive: Collection<Author>;
mutuallyRecursive.find({});
mutuallyRecursive.find({
b: { a: { b: { a: null } } }
expectAssignable<Filter<Author>>({
favoritePublication: {
title: 'book title',
author: {
name: 'author name'
}
}
});
expectNotType<UpdateFilter<Author>>({
$set: {
favoritePublication: {
title: 'a title',
published: new Date(),
author: {
name: 23
}
}
}
});

// Extremely deep type checking for recursive schemas
Expand Down

0 comments on commit 18e267c

Please sign in to comment.