Skip to content

Commit 18e267c

Browse files
committed
test: add example of explicit embedded usage
1 parent 42c9507 commit 18e267c

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

test/types/community/collection/recursive-types.test-d.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
import { expectAssignable, expectError, expectNotAssignable } from 'tsd';
1+
import { expectAssignable, expectError, expectNotAssignable, expectNotType } from 'tsd';
22

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

55
/**
66
* mutually recursive types are not supported and will not get type safety
77
*/
88
interface Author {
9-
books: Book[];
10-
favoritePublication: Book;
119
name: string;
10+
favoritePublication: Book;
1211
}
1312

1413
interface Book {
15-
author: Author;
1614
title: string;
17-
published: Date;
15+
author: Author;
1816
}
1917

20-
declare const mutuallyRecursive: Collection<Author>;
21-
mutuallyRecursive.find({});
22-
mutuallyRecursive.find({
23-
b: { a: { b: { a: null } } }
18+
expectAssignable<Filter<Author>>({
19+
favoritePublication: {
20+
title: 'book title',
21+
author: {
22+
name: 'author name'
23+
}
24+
}
25+
});
26+
expectNotType<UpdateFilter<Author>>({
27+
$set: {
28+
favoritePublication: {
29+
title: 'a title',
30+
published: new Date(),
31+
author: {
32+
name: 23
33+
}
34+
}
35+
}
2436
});
2537

2638
// Extremely deep type checking for recursive schemas

0 commit comments

Comments
 (0)