Skip to content

Commit 1a9ce3a

Browse files
committed
Fix parameterize types
1 parent cdf8bc5 commit 1a9ce3a

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

packages/core/src/exports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { logger } from './utils-hoist/logger';
2323
import { uuid4 } from './utils-hoist/misc';
2424
import { timestampInSeconds } from './utils-hoist/time';
2525
import { GLOBAL_OBJ } from './utils-hoist/worldwide';
26-
import { parameterize } from './utils/parameterize';
26+
import { parameterizeAny } from './utils/parameterize';
2727
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
2828
import { parseEventHintOrCaptureContext } from './utils/prepareEvent';
2929

@@ -436,7 +436,7 @@ export const _experiment_log = {
436436
* Sentry._experiment_log.fmt`This is a log statement with ${x} and ${y} params`
437437
* ```
438438
*/
439-
fmt: parameterize,
439+
fmt: parameterizeAny<string | number | null | object>,
440440

441441
/**
442442
* A flexible utility to record a log with a custom level and send it to sentry.

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export { hasTracingEnabled } from './utils/hasSpansEnabled';
6767
export { hasSpansEnabled } from './utils/hasSpansEnabled';
6868
export { isSentryRequestUrl } from './utils/isSentryRequestUrl';
6969
export { handleCallbackErrors } from './utils/handleCallbackErrors';
70-
export { parameterize } from './utils/parameterize';
70+
export { parameterize } from './utils/parameterize';
71+
7172
export { addAutoIpAddressToSession, addAutoIpAddressToUser } from './utils/ipAddress';
7273
export {
7374
convertSpanLinksForEnvelope,

packages/core/src/types-hoist/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export type {
153153

154154
export type { BrowserClientReplayOptions, BrowserClientProfilingOptions } from './browseroptions';
155155
export type { CheckIn, MonitorConfig, FinishedCheckIn, InProgressCheckIn, SerializedCheckIn } from './checkin';
156-
export type { ParameterizedString } from './parameterize';
156+
export type { ParameterizedString, ParameterizedAnyValueString } from './parameterize';
157157
export type { ContinuousProfiler, ProfilingIntegration, Profiler } from './profiling';
158158
export type { ViewHierarchyData, ViewHierarchyWindow } from './view-hierarchy';
159159
export type { LegacyCSPReport } from './csp';
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export type ParameterizedString = string & {
1+
export type ParameterizedAnyValueString<T> = string & {
22
__sentry_template_string__?: string;
3-
__sentry_template_values__?: string[];
3+
__sentry_template_values__?: T[];
44
};
5+
6+
export type ParameterizedString = ParameterizedAnyValueString<string>;

packages/core/src/utils/parameterize.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ParameterizedString } from '../types-hoist';
1+
import type { ParameterizedAnyValueString } from '../types-hoist';
22

33
/**
44
* Tagged template function which returns parameterized representation of the message
@@ -8,9 +8,21 @@ import type { ParameterizedString } from '../types-hoist';
88
* @param strings An array of string values splitted between expressions
99
* @param values Expressions extracted from template string
1010
* @returns String with template information in __sentry_template_string__ and __sentry_template_values__ properties
11+
* @deprecated Use parameterizeAny instead
1112
*/
12-
export function parameterize(strings: TemplateStringsArray, ...values: string[]): ParameterizedString {
13-
const formatted = new String(String.raw(strings, ...values)) as ParameterizedString;
13+
export const parameterize = parameterizeAny<string>;
14+
15+
/**
16+
* Tagged template function which returns parameterized representation of the message
17+
* For example: parameterize`This is a log statement with ${x} and ${y} params`, would return:
18+
* "__sentry_template_string__": 'This is a log statement with %s and %s params',
19+
* "__sentry_template_values__": ['first', 'second']
20+
* @param strings An array of string values splitted between expressions
21+
* @param values Expressions extracted from template string, types provided by the generic.
22+
* @returns String with template information in __sentry_template_string__ and __sentry_template_values__ properties
23+
*/
24+
export function parameterizeAny<T>(strings: TemplateStringsArray, ...values: T[]): ParameterizedAnyValueString<T> {
25+
const formatted = new String(String.raw(strings, ...values)) as ParameterizedAnyValueString<T>;
1426
formatted.__sentry_template_string__ = strings.join('\x00').replace(/%/g, '%%').replace(/\0/g, '%s');
1527
formatted.__sentry_template_values__ = values;
1628
return formatted;

0 commit comments

Comments
 (0)