-
Notifications
You must be signed in to change notification settings - Fork 213
/
typingsSpec.ts
22 lines (17 loc) · 1006 Bytes
/
typingsSpec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* Run using `npm run test-typings`
* The sole fact that this file compiles means that typings work
* This follows how DefinitelyTyped tests work
* @see https://stackoverflow.com/questions/49296151/how-to-write-tests-for-typescript-typing-definition
*/
import jsonpatch from '../../..';
import * as jsonpatchStar from '../../..';
import { applyPatch, Operation } from '../../..';
const document = { firstName: "Albert", contactDetails: { phoneNumbers: [] } };
const typedPatch = new Array<Operation>({ op: "replace", path: "/firstName", value: "Joachim" });
const untypedPatch = [{ op: "replace", path: "/firstName", value: "Joachim" }];
const test_jsonpatch = jsonpatch.applyPatch(document, typedPatch).newDocument;
const test_jsonpatchStar = jsonpatchStar.applyPatch(document, typedPatch).newDocument;
const test_applyPatch = applyPatch(document, typedPatch).newDocument;
// the below line would NOT compile with TSC
// const test_applyPatch = applyPatch(document, untypedPatch).newDocument;