Skip to content

Commit

Permalink
fix(replay): Add missing rrweb type declarations (#6464)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lms24 committed Dec 7, 2022
1 parent 0434474 commit c68d429
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/replay/src/types.ts
@@ -1,7 +1,7 @@
import type { eventWithTime, recordOptions } from 'rrweb/typings/types';
import type { eventWithTime, recordOptions } from './types/rrweb';

export type RecordingEvent = eventWithTime;
export type RecordingOptions = recordOptions<eventWithTime>;
export type RecordingOptions = recordOptions;

export type RecordedEvents = Uint8Array | string;

Expand Down
38 changes: 38 additions & 0 deletions packages/replay/src/types/rrweb.ts
@@ -0,0 +1,38 @@
/* eslint-disable @typescript-eslint/naming-convention */

type blockClass = string | RegExp;
type maskTextClass = string | RegExp;

enum EventType {
DomContentLoaded = 0,
Load = 1,
FullSnapshot = 2,
IncrementalSnapshot = 3,
Meta = 4,
Custom = 5,
Plugin = 6,
}

/**
* This is a partial copy of rrweb's eventWithTime type which only contains the properties
* we specifcally need in the SDK.
*/
export type eventWithTime = {
type: EventType;
data: unknown;
timestamp: number;
delay?: number;
};

/**
* This is a partial copy of rrweb's recording options which only contains the properties
* we specifically us in the SDK. Users can specify additional properties, hence we add the
* Record<string, unknown> union type.
*/
export type recordOptions = {
maskAllInputs?: boolean;
blockClass?: blockClass;
ignoreClass?: string;
maskTextClass?: maskTextClass;
blockSelector?: string;
} & Record<string, unknown>;

0 comments on commit c68d429

Please sign in to comment.