Skip to content

Commit c68d429

Browse files
authored
fix(replay): Add missing rrweb type declarations (#6464)
To generate type declarations, we use `tsc` (`yarn build:types`) which doesn't pull external type declarations into the resulting `.d.ts` files. We import types from rrweb which our internal types rely on. Because we now vendor rrweb, the rrweb-internal types are no longer getting installed in our users node_modules, producing typescript errors when they build their projects. To hotfix this, this PR vendors a "light" version of the two rrweb types we use.
1 parent 0434474 commit c68d429

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/replay/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { eventWithTime, recordOptions } from 'rrweb/typings/types';
1+
import type { eventWithTime, recordOptions } from './types/rrweb';
22

33
export type RecordingEvent = eventWithTime;
4-
export type RecordingOptions = recordOptions<eventWithTime>;
4+
export type RecordingOptions = recordOptions;
55

66
export type RecordedEvents = Uint8Array | string;
77

packages/replay/src/types/rrweb.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
type blockClass = string | RegExp;
4+
type maskTextClass = string | RegExp;
5+
6+
enum EventType {
7+
DomContentLoaded = 0,
8+
Load = 1,
9+
FullSnapshot = 2,
10+
IncrementalSnapshot = 3,
11+
Meta = 4,
12+
Custom = 5,
13+
Plugin = 6,
14+
}
15+
16+
/**
17+
* This is a partial copy of rrweb's eventWithTime type which only contains the properties
18+
* we specifcally need in the SDK.
19+
*/
20+
export type eventWithTime = {
21+
type: EventType;
22+
data: unknown;
23+
timestamp: number;
24+
delay?: number;
25+
};
26+
27+
/**
28+
* This is a partial copy of rrweb's recording options which only contains the properties
29+
* we specifically us in the SDK. Users can specify additional properties, hence we add the
30+
* Record<string, unknown> union type.
31+
*/
32+
export type recordOptions = {
33+
maskAllInputs?: boolean;
34+
blockClass?: blockClass;
35+
ignoreClass?: string;
36+
maskTextClass?: maskTextClass;
37+
blockSelector?: string;
38+
} & Record<string, unknown>;

0 commit comments

Comments
 (0)