|
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' |
10 | 2 | import {MessageFormatElement} from '@formatjs/icu-messageformat-parser'
|
| 3 | +import {DisplayNames, DisplayNamesOptions} from '@formatjs/intl-displaynames' |
11 | 4 | import IntlListFormat, {
|
12 | 5 | IntlListFormatOptions,
|
13 | 6 | Part,
|
14 | 7 | } from '@formatjs/intl-listformat'
|
15 |
| -import {DisplayNames, DisplayNamesOptions} from '@formatjs/intl-displaynames' |
16 | 8 | 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, |
18 | 18 | MessageFormatError,
|
19 | 19 | MissingDataError,
|
20 |
| - InvalidConfigError, |
| 20 | + MissingTranslationError, |
21 | 21 | UnsupportedFormatterError,
|
22 | 22 | } from './error'
|
23 | 23 | import {DEFAULT_INTL_CONFIG} from './utils'
|
24 |
| -import {NumberFormatOptions} from '@formatjs/ecma402-abstract' |
25 | 24 |
|
26 | 25 | // Note: FormatjsIntl is defined as a global namespace so the library user can
|
27 | 26 | // override the default types of Message.ids (e.g. as string literal unions from extracted strings)
|
@@ -119,99 +118,126 @@ export type FormatDisplayNameOptions = Omit<
|
119 | 118 | */
|
120 | 119 | export interface IntlFormatters<TBase = unknown> {
|
121 | 120 | formatDateTimeRange(
|
| 121 | + this: void, |
122 | 122 | from: Parameters<DateTimeFormat['formatRange']>[0],
|
123 | 123 | to: Parameters<DateTimeFormat['formatRange']>[1],
|
124 | 124 | opts?: FormatDateOptions
|
125 | 125 | ): string
|
126 | 126 | formatDate(
|
| 127 | + this: void, |
127 | 128 | value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
|
128 | 129 | opts?: FormatDateOptions
|
129 | 130 | ): string
|
130 | 131 | formatTime(
|
| 132 | + this: void, |
131 | 133 | value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
|
132 | 134 | opts?: FormatDateOptions
|
133 | 135 | ): string
|
134 | 136 | formatDateToParts(
|
| 137 | + this: void, |
135 | 138 | value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
|
136 | 139 | opts?: FormatDateOptions
|
137 | 140 | ): Intl.DateTimeFormatPart[]
|
138 | 141 | formatTimeToParts(
|
| 142 | + this: void, |
139 | 143 | value: Parameters<Intl.DateTimeFormat['format']>[0] | string,
|
140 | 144 | opts?: FormatDateOptions
|
141 | 145 | ): Intl.DateTimeFormatPart[]
|
142 | 146 | formatRelativeTime(
|
| 147 | + this: void, |
143 | 148 | value: Parameters<Intl.RelativeTimeFormat['format']>[0],
|
144 | 149 | unit?: Parameters<Intl.RelativeTimeFormat['format']>[1],
|
145 | 150 | opts?: FormatRelativeTimeOptions
|
146 | 151 | ): string
|
147 | 152 | formatNumber(
|
| 153 | + this: void, |
148 | 154 | value: Parameters<Intl.NumberFormat['format']>[0],
|
149 | 155 | opts?: FormatNumberOptions
|
150 | 156 | ): string
|
151 | 157 | formatNumberToParts(
|
| 158 | + this: void, |
152 | 159 | value: Parameters<Intl.NumberFormat['format']>[0],
|
153 | 160 | opts?: FormatNumberOptions
|
154 | 161 | ): Intl.NumberFormatPart[]
|
155 | 162 | formatPlural(
|
| 163 | + this: void, |
156 | 164 | value: Parameters<Intl.PluralRules['select']>[0],
|
157 | 165 | opts?: FormatPluralOptions
|
158 | 166 | ): ReturnType<Intl.PluralRules['select']>
|
159 | 167 | formatMessage(
|
| 168 | + this: void, |
160 | 169 | descriptor: MessageDescriptor,
|
161 | 170 | values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>,
|
162 | 171 | opts?: IntlMessageFormatOptions
|
163 | 172 | ): string
|
164 | 173 | formatMessage<T extends TBase>(
|
| 174 | + this: void, |
165 | 175 | descriptor: MessageDescriptor,
|
166 | 176 | values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>,
|
167 | 177 | opts?: IntlMessageFormatOptions
|
168 | 178 | ): string | T | (T | string)[]
|
169 | 179 | $t(
|
| 180 | + this: void, |
170 | 181 | descriptor: MessageDescriptor,
|
171 | 182 | values?: Record<string, PrimitiveType | FormatXMLElementFn<string, string>>,
|
172 | 183 | opts?: IntlMessageFormatOptions
|
173 | 184 | ): string
|
174 | 185 | $t<T extends TBase>(
|
| 186 | + this: void, |
175 | 187 | descriptor: MessageDescriptor,
|
176 | 188 | values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>,
|
177 | 189 | opts?: IntlMessageFormatOptions
|
178 | 190 | ): 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 |
180 | 196 | formatList<T extends TBase>(
|
| 197 | + this: void, |
181 | 198 | values: ReadonlyArray<string | T>,
|
182 | 199 | opts?: FormatListOptions
|
183 | 200 | ): T | string | (string | T)[]
|
184 | 201 | formatListToParts<T extends TBase>(
|
| 202 | + this: void, |
185 | 203 | values: ReadonlyArray<string | T>,
|
186 | 204 | opts?: FormatListOptions
|
187 | 205 | ): Part[]
|
188 | 206 | formatDisplayName(
|
| 207 | + this: void, |
189 | 208 | value: Parameters<DisplayNames['of']>[0],
|
190 | 209 | opts: FormatDisplayNameOptions
|
191 | 210 | ): string | undefined
|
192 | 211 | }
|
193 | 212 |
|
194 | 213 | export interface Formatters {
|
195 | 214 | getDateTimeFormat(
|
| 215 | + this: void, |
196 | 216 | ...args: ConstructorParameters<typeof Intl.DateTimeFormat>
|
197 | 217 | ): DateTimeFormat
|
198 | 218 | getNumberFormat(
|
| 219 | + this: void, |
199 | 220 | locales?: string | string[],
|
200 | 221 | opts?: NumberFormatOptions
|
201 | 222 | ): Intl.NumberFormat
|
202 | 223 | getMessageFormat(
|
| 224 | + this: void, |
203 | 225 | ...args: ConstructorParameters<typeof IntlMessageFormat>
|
204 | 226 | ): IntlMessageFormat
|
205 | 227 | getRelativeTimeFormat(
|
| 228 | + this: void, |
206 | 229 | ...args: ConstructorParameters<typeof Intl.RelativeTimeFormat>
|
207 | 230 | ): Intl.RelativeTimeFormat
|
208 | 231 | getPluralRules(
|
| 232 | + this: void, |
209 | 233 | ...args: ConstructorParameters<typeof Intl.PluralRules>
|
210 | 234 | ): Intl.PluralRules
|
211 | 235 | getListFormat(
|
| 236 | + this: void, |
212 | 237 | ...args: ConstructorParameters<typeof IntlListFormat>
|
213 | 238 | ): IntlListFormat
|
214 | 239 | getDisplayNames(
|
| 240 | + this: void, |
215 | 241 | ...args: ConstructorParameters<typeof DisplayNames>
|
216 | 242 | ): DisplayNames
|
217 | 243 | }
|
|
0 commit comments