Skip to content

Commit fb267e0

Browse files
authored
fix(types): Vendor in TextEncoderCommon type (#5221)
`TextEncoderCommon` is a type from `lib.dom.d.ts`. We don't want to require users to set DOM types, so we vendor it in. It's a relatively simple type, so we don't have to worry about potential conflicts or user issues.
1 parent fb1c284 commit fb267e0

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

Diff for: packages/types/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export type { Severity, SeverityLevel } from './severity';
6262
export type { Span, SpanContext } from './span';
6363
export type { StackFrame } from './stackframe';
6464
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
65+
export type { TextEncoderInternal } from './textencoder';
6566
export type {
6667
CustomSamplingContext,
6768
Measurements,

Diff for: packages/types/src/textencoder.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Vendored type from TS 3.8 `typescript/lib/lib.dom.d.ts`.
3+
*
4+
* Type is vendored in so that users don't have to opt-in to DOM types.
5+
*/
6+
export interface TextEncoderCommon {
7+
/**
8+
* Returns "utf-8".
9+
*/
10+
readonly encoding: string;
11+
}
12+
13+
// Combination of global TextEncoder and Node require('util').TextEncoder
14+
export interface TextEncoderInternal extends TextEncoderCommon {
15+
encode(input?: string): Uint8Array;
16+
}

Diff for: packages/types/src/transport.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { EventDropReason } from './clientreport';
22
import { DataCategory } from './datacategory';
33
import { Envelope } from './envelope';
4+
import { TextEncoderInternal } from './textencoder';
45

56
export type TransportRequest = {
67
body: string | Uint8Array;
@@ -15,11 +16,6 @@ export type TransportMakeRequestResponse = {
1516
};
1617
};
1718

18-
// Combination of global TextEncoder and Node require('util').TextEncoder
19-
interface TextEncoderInternal extends TextEncoderCommon {
20-
encode(input?: string): Uint8Array;
21-
}
22-
2319
export interface InternalBaseTransportOptions {
2420
bufferSize?: number;
2521
recordDroppedEvent: (reason: EventDropReason, dataCategory: DataCategory) => void;

Diff for: packages/utils/src/envelope.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Attachment, AttachmentItem, DataCategory, Envelope, EnvelopeItem, EnvelopeItemType } from '@sentry/types';
1+
import {
2+
Attachment,
3+
AttachmentItem,
4+
DataCategory,
5+
Envelope,
6+
EnvelopeItem,
7+
EnvelopeItemType,
8+
TextEncoderInternal,
9+
} from '@sentry/types';
210

311
import { dropUndefinedKeys } from './object';
412

@@ -36,11 +44,6 @@ export function forEachEnvelopeItem<E extends Envelope>(
3644
});
3745
}
3846

39-
// Combination of global TextEncoder and Node require('util').TextEncoder
40-
interface TextEncoderInternal extends TextEncoderCommon {
41-
encode(input?: string): Uint8Array;
42-
}
43-
4447
function encodeUTF8(input: string, textEncoder?: TextEncoderInternal): Uint8Array {
4548
const utf8 = textEncoder || new TextEncoder();
4649
return utf8.encode(input);

0 commit comments

Comments
 (0)