What is @rrweb/types?
@rrweb/types is a TypeScript type definition package for rrweb, a library for recording and replaying user interactions on web pages. This package provides type definitions for various events and data structures used in rrweb, making it easier to work with rrweb in TypeScript projects.
What are @rrweb/types's main functionalities?
Event Types
Defines the structure of an event with time, which includes the type of event, data associated with the event, timestamp, and delay.
import { eventWithTime } from '@rrweb/types';
const event: eventWithTime = {
type: 1,
data: {},
timestamp: Date.now(),
delay: 0
};
Incremental Snapshot Event
Defines the structure of an incremental snapshot event, which includes the type of event, data related to the snapshot, timestamp, and delay.
import { incrementalSnapshotEvent } from '@rrweb/types';
const snapshotEvent: incrementalSnapshotEvent = {
type: 2,
data: {
source: 1,
positions: [{ x: 0, y: 0, id: 1 }]
},
timestamp: Date.now(),
delay: 0
};
Full Snapshot Event
Defines the structure of a full snapshot event, which includes the type of event, data related to the full snapshot, timestamp, and delay.
import { fullSnapshotEvent } from '@rrweb/types';
const fullSnapshot: fullSnapshotEvent = {
type: 3,
data: {
node: {
id: 1,
type: 1,
childNodes: []
}
},
timestamp: Date.now(),
delay: 0
};
Other packages similar to @rrweb/types
typescript
TypeScript is a superset of JavaScript that adds static types. While it doesn't provide specific types for rrweb, it allows you to define your own types and interfaces, offering flexibility and type safety in your projects.
io-ts
io-ts is a runtime type system for IO decoding/encoding in TypeScript. It allows you to define types and validate data at runtime, which can be useful for ensuring the correctness of data structures similar to those used in rrweb.
zod
Zod is a TypeScript-first schema declaration and validation library. It provides a way to define and validate data structures, similar to the type definitions provided by @rrweb/types, but with additional runtime validation capabilities.