8000 docs(NODE-6302): add SerializableTypes to migration guide (#716) · mongodb/js-bson@e584fbb · GitHub
[go: up one dir, main page]

Skip to content

Commit e584fbb

Browse files
nbbeekendariakp
andauthored
docs(NODE-6302): add SerializableTypes to migration guide (#716)
Co-authored-by: Daria Pardue <daria.pardue@mongodb.com>
1 parent 5a8900e commit e584fbb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/upgrade-to-v5.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Other Changes](#other-changes)
1111
- [`serializeFunctions` bug fix](#serializefunctions-bug-fix)
1212
- [TS "target" set to es2020](#ts-target-set-to-es2020)
13+
- [Removed SerializableTypes](#removed-serializabletypes)
1314

1415
## About
1516

@@ -313,3 +314,15 @@ import { serialize } from 'bson5';
313314
serialize({ _id: new ObjectId() });
314315
// Uncaught BSONVersionError: Unsupported BSON version, bson types must be from bson 5.0 or later
315316
```
317+
318+
### Removed SerializableTypes
319+
320+
```ts
321+
export type JSONPrimitive = string | number | boolean | null;
322+
export type SerializableTypes = Document | Array<JSONPrimitive | Document> | JSONPrimitive;
323+
```
324+
325+
`SerializableTypes` is removed in v5 due to its inaccuracy and inconvenience when working with return type of `EJSON.parse()`.
326+
This type does not contain all possible outputs from this function and it cannot be conveniently related to a custom declared type.
327+
`EJSON.parse` and `EJSON.stringify` now accept `any` in alignment with `JSON`'s corresponding APIs.
328+
For users that desire type strictness it is recommended to wrap these APIs with type annotations that take/return `unknown` since that generally forces better narrowing logic than `SerializableTypes` would have prompted.

0 commit comments

Comments
 (0)
0