Skip to content

Commit a9ba729

Browse files
committed
fix(@formatjs/intl): add this: void to IntlShape method, fix #4133
1 parent f71ce48 commit a9ba729

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

packages/intl/src/types.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
import {
2-
IntlMessageFormat,
3-
Formats,
4-
FormatXMLElementFn,
5-
FormatError,
6-
PrimitiveType,
7-
Options as IntlMessageFormatOptions,
8-
} from 'intl-messageformat'
9-
import {DateTimeFormat} from '@formatjs/ecma402-abstract'
1+
import {DateTimeFormat, NumberFormatOptions} from '@formatjs/ecma402-abstract'
102
import {MessageFormatElement} from '@formatjs/icu-messageformat-parser'
3+
import {DisplayNames, DisplayNamesOptions} from '@formatjs/intl-displaynames'
114
import IntlListFormat, {
125
IntlListFormatOptions,
136
Part,
147
} from '@formatjs/intl-listformat'
15-
import {DisplayNames, DisplayNamesOptions} from '@formatjs/intl-displaynames'
168
import {
17-
MissingTranslationError,
9+
FormatError,
10+
Formats,
11+
FormatXMLElementFn,
12+
IntlMessageFormat,
13+
Options as IntlMessageFormatOptions,
14+
PrimitiveType,
15+
} from 'intl-messageformat'
16+
import {
17+
InvalidConfigError,
1818
MessageFormatError,
1919
MissingDataError,
20-
InvalidConfigError,
20+
MissingTranslationError,
2121
UnsupportedFormatterError,
2222
} from './error'
2323
import {DEFAULT_INTL_CONFIG} from './utils'
24-
import {NumberFormatOptions} from '@formatjs/ecma402-abstract'
2524

2625
// Note: FormatjsIntl is defined as a global namespace so the library user can
2726
// override the default types of Message.ids (e.g. as string literal unions from extracted strings)
@@ -119,99 +118,126 @@ export type FormatDisplayNameOptions = Omit<
119118
*/
120119
export interface IntlFormatters<TBase = unknown> {
121120
formatDateTimeRange(
121+
this: void,
122122
from: Parameters<DateTimeFormat['formatRange']>[0],
123123
to: Parameters<DateTimeFormat['formatRange']>[1],
124124
opts?: FormatDateOptions
125125
): string
126126
formatDate(
127+
this: void,
127128
value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
128129
opts?: FormatDateOptions
129130
): string
130131
formatTime(
132+
this: void,
131133
value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
132134
opts?: FormatDateOptions
133135
): string
134136
formatDateToParts(
137+
this: void,
135138
value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
136139
opts?: FormatDateOptions
137140
): Intl.DateTimeFormatPart[]
138141
formatTimeToParts(
142+
this: void,
139143
value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
140144
opts?: FormatDateOptions
141145
): Intl.DateTimeFormatPart[]
142146
formatRelativeTime(
147+
this: void,
143148
value: Parameters<Intl.RelativeTimeFormat['format']>[0],
144149
unit?: Parameters<Intl.RelativeTimeFormat['format']>[1],
145150
opts?: FormatRelativeTimeOptions
146151
): string
147152
formatNumber(
153+
this: void,
148154
value: Parameters<Intl.NumberFormat['format']>[0],
149155
opts?: FormatNumberOptions
150156
): string
151157
formatNumberToParts(
158+
this: void,
152159
value: Parameters<Intl.NumberFormat['format']>[0],
153160
opts?: FormatNumberOptions
154161
): Intl.NumberFormatPart[]
155162
formatPlural(
163+
this: void,
156164
value: Parameters<Intl.PluralRules['select']>[0],
157165
opts?: FormatPluralOptions
158166
): ReturnType<Intl.PluralRules['select']>
159167
formatMessage(
168+
this: void,
160169
descriptor: MessageDescriptor,
161170
values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>,
162171
opts?: IntlMessageFormatOptions
163172
): string
164173
formatMessage<T extends TBase>(
174+
this: void,
165175
descriptor: MessageDescriptor,
166176
values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>,
167177
opts?: IntlMessageFormatOptions
168178
): string | T | (T | string)[]
169179
$t(
180+
this: void,
170181
descriptor: MessageDescriptor,
171182
values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>,
172183
opts?: IntlMessageFormatOptions
173184
): string
174185
$t<T extends TBase>(
186+
this: void,
175187
descriptor: MessageDescriptor,
176188
values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>,
177189
opts?: IntlMessageFormatOptions
178190
): string | T | (T | string)[]
179-
formatList(values: ReadonlyArray<string>, opts?: FormatListOptions): string
191+
formatList(
192+
this: void,
193+
values: ReadonlyArray<string>,
194+
opts?: FormatListOptions
195+
): string
180196
formatList<T extends TBase>(
197+
this: void,
181198
values: ReadonlyArray<string | T>,
182199
opts?: FormatListOptions
183200
): T | string | (string | T)[]
184201
formatListToParts<T extends TBase>(
202+
this: void,
185203
values: ReadonlyArray<string | T>,
186204
opts?: FormatListOptions
187205
): Part[]
188206
formatDisplayName(
207+
this: void,
189208
value: Parameters<DisplayNames['of']>[0],
190209
opts: FormatDisplayNameOptions
191210
): string | undefined
192211
}
193212

194213
export interface Formatters {
195214
getDateTimeFormat(
215+
this: void,
196216
...args: ConstructorParameters<typeof Intl.DateTimeFormat>
197217
): DateTimeFormat
198218
getNumberFormat(
219+
this: void,
199220
locales?: string | string[],
200221
opts?: NumberFormatOptions
201222
): Intl.NumberFormat
202223
getMessageFormat(
224+
this: void,
203225
...args: ConstructorParameters<typeof IntlMessageFormat>
204226
): IntlMessageFormat
205227
getRelativeTimeFormat(
228+
this: void,
206229
...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>
207230
): Intl.RelativeTimeFormat
208231
getPluralRules(
232+
this: void,
209233
...args: ConstructorParameters<typeof Intl.PluralRules>
210234
): Intl.PluralRules
211235
getListFormat(
236+
this: void,
212237
...args: ConstructorParameters<typeof IntlListFormat>
213238
): IntlListFormat
214239
getDisplayNames(
240+
this: void,
215241
...args: ConstructorParameters<typeof DisplayNames>
216242
): DisplayNames
217243
}

packages/react-intl/src/components/useIntl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react'
2-
import {Context} from './injectIntl'
3-
import {invariantIntlContext} from '../utils'
42
import {IntlShape} from '../types'
3+
import {invariantIntlContext} from '../utils'
4+
import {Context} from './injectIntl'
55

6-
export default function useIntl(): IntlShape {
6+
export default function useIntl(this: void): IntlShape {
77
const intl = React.useContext(Context)
88
invariantIntlContext(intl)
99
return intl

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy