You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You cannot specify a recursive type as a type parameter for {+driver-long+}
91
-
classes. Click the following tabs to see a recursive type and a code snippet that
92
-
uses the recursive type and raises an error:
93
-
94
-
.. tabs::
95
-
96
-
.. tab:: Recursive Type
97
-
:tabid: recursive-type
98
-
99
-
.. code-block:: typescript
89
+
classes. The following code snippet defines a recursive type:
100
90
101
-
interface RecursiveType {
102
-
r: RecursiveType | BaseCase;
103
-
i: number;
104
-
}
91
+
.. code-block:: typescript
105
92
106
-
type BaseCase = "done";
93
+
interface RecursiveType {
94
+
r: RecursiveType | BaseCase;
95
+
i: number;
96
+
}
107
97
108
-
.. tab:: Code Snippet
109
-
:tabid: code-snippet
98
+
type BaseCase = "done";
110
99
111
-
The following code snippet uses a recursive type:
100
+
The following code snippet uses the preceding recursive type:
112
101
113
-
.. code-block:: typescript
102
+
.. code-block:: typescript
114
103
115
-
const database = client.db("test-db");
116
-
const col = database.collection<RecursiveType>("test-collection");
117
-
const document = await col.findOne({ i: 1 });
104
+
const database = client.db("<your db>");
105
+
const col = database.collection<RecursiveType>("<your collection>");
106
+
const document = await col.findOne({ i: 1 });
118
107
119
-
The preceding code snippet raises the following error at compile time:
108
+
The preceding code snippet raises the following error at compile time:
120
109
121
-
.. code-block:: text
110
+
.. code-block:: text
122
111
123
-
error TS2615: Type of property 'r' circularly references itself in mapped type '{ [Key in keyof RecursiveType]: [Key, ...NestedPaths<RecursiveType[Key]>]; }'.
112
+
error TS2615: Type of property 'r' circularly references itself in mapped type '{ [Key in keyof RecursiveType]: [Key, ...NestedPaths<RecursiveType[Key]>]; }'.
124
113
125
-
If you must use a recursive type to specify a schema for your documents,
126
-
use version 4.2 of the {+driver-long+}.
114
+
If you must use a recursive type as your document schema, use version 4.2 of
115
+
the {+driver-long+}.
127
116
128
-
To track the progress of mitigating this limitation in version {+version+} of
129
-
the driver, see `this ticket <https://jira.mongodb.org/browse/NODE-3852>`__
0 commit comments