-
Notifications
You must be signed in to change notification settings - Fork 2
api‐zimic
github-actions[bot] edited this page Aug 25, 2024
·
2 revisions
The module zimic
exports general resources and utility types used by Zimic.
-
zimic/http
: HTTP resources. -
zimic/interceptor
: API mocking and interceptor resources.-
zimic/interceptor/http
: HTTP interceptor resources. -
zimic/interceptor/server
: programmatic interceptor server resources.
-
-
zimic/typegen
: programmatic type generation resources.
Tip
All APIs are documented using JSDoc and visible directly in your IDE.
Represents or validates a type that is compatible with JSON.
import { type JSONValue } from 'zimic';
// Can be used as a standalone type:
const value: JSONValue = {
name: 'example',
tags: ['one', 'two'],
};
import { type JSONValue } from 'zimic';
// Can be used with a type argument to validate a JSON value:
type ValidJSON = JSONValue<{
id: string;
email: string;
createdAt: string;
}>;
// This results in a type error:
type InvalidJSON = JSONValue<{
id: string;
email: string;
createdAt: Date; // `Date` is not a valid JSON value.
save(): Promise<void>; // Functions are not valid JSON values.
}>;
Important
The input of JSONValue
and all of its internal types must be declared inline or as a type aliases (type
). They
cannot be interfaces.
Recursively converts a type to its JSON-serialized version. Dates are converted to strings and keys with non-JSON values are excluded.
import { type JSONSerialized } from 'zimic';
type SerializedUser = JSONSerialized<{
id: string;
email: string;
createdAt: Date;
save(): Promise<void>;
}>;
// {
// id: string;
// email: string;
// createdAt: string;
// }
© Zimic
npm |
Docs | Issues |
Examples | Roadmap
Help us improve these docs!
Report an issue or
edit on GitHub.