@discord/intl 0.8.0-rc.0 → 0.8.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,7 +46,7 @@ export declare class IntlManager {
46
46
  * For static messages with no rich text and no dynamic placeholders, use this method to
47
47
  * immediately return the plain string value of the message in the current locale.
48
48
  */
49
- string<T extends TypedIntlMessageGetter<undefined>>(message: T): string;
49
+ string<T extends TypedIntlMessageGetter<{}>>(message: T): string;
50
50
  /**
51
51
  * Return a raw string representing the syntax of the original message, as
52
52
  * authored, with no values replaced. The result of this function could be
package/dist/types.d.ts CHANGED
@@ -49,11 +49,10 @@ export interface IntlMessageGetter extends IntlMessageGetterAdditions {
49
49
  /**
50
50
  * Getter function that retrieves a message that best matches the requested
51
51
  * locale. `FormatValues` represents either an object containing all of the
52
- * value types that are required to format the message, or `undefined` to
53
- * represent that there are no values required and the message is a plain
54
- * string.
52
+ * value types that are required to format the message, or `{}` to represent
53
+ * that there are no values required and the message is a plain string.
55
54
  */
56
- export interface TypedIntlMessageGetter<FormatValues extends object | undefined>
55
+ export interface TypedIntlMessageGetter<FormatValues extends object>
57
56
  extends IntlMessageGetterAdditions {
58
57
  // TODO: This is lossy and unfortunate that typing can't be propagated
59
58
  // to the returned message type, but doing so causes problems with
@@ -94,11 +93,7 @@ export interface TypedIntlMessageGetter<FormatValues extends object | undefined>
94
93
  * downstream will ensure that all format values are always checked for all
95
94
  * possible cases of the message.
96
95
  */
97
- __phantom: object extends FormatValues
98
- ? any
99
- : FormatValues extends undefined
100
- ? any
101
- : keyof FormatValues;
96
+ __phantom: object extends FormatValues ? any : {} extends FormatValues ? any : keyof FormatValues;
102
97
  }
103
98
 
104
99
  /**
@@ -145,7 +140,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
145
140
  * If T is a union of message types including both rich messages requiring
146
141
  * values _and_ plain string messages with no values, this type will still
147
142
  * properly resolve all of the required values, assuming that the getters for
148
- * the plain messages use the convention of passing `undefined` as the generic
143
+ * the plain messages use the convention of passing `{}` as the generic
149
144
  * argument, representing "no values should be passed for this message".
150
145
  *
151
146
  *
@@ -173,13 +168,13 @@ export type FormatValuesFor<T> =
173
168
  // be supplied, represented by the `never`. This prevents accidentally
174
169
  // passing an object, even an empty one, for those strings, and allows the
175
170
  // formatter to optimize a little more on each call.
176
- [T] extends [undefined]
171
+ [{}] extends [T]
177
172
  ? never
178
173
  : // The `never` condition needs to be repeated here, but this time _without_
179
174
  // the `[]` syntax, so that only the union elements with actual values are
180
175
  // included in the union. Without this, the `infer U` on the latter side
181
176
  // fails to resolve and the type just becomes `never`.
182
- UnionToIntersection<T extends undefined ? never : T>;
177
+ UnionToIntersection<{} extends T ? never : T>;
183
178
 
184
179
  /**
185
180
  * A template type for replaceable placeholder types to be defined by formatter
@@ -254,7 +249,7 @@ export type RequiredFormatValues<
254
249
  Values extends IntlMessageGetter,
255
250
  FunctionTypes extends FunctionTypeMap,
256
251
  > =
257
- IntlMessageGetterInnerType<Values> extends undefined
252
+ {} extends IntlMessageGetterInnerType<Values>
258
253
  ? {}
259
254
  : CheckStrictAny<
260
255
  IntlMessageGetterInnerType<Values>,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl",
3
- "version": "0.8.0-rc.0",
3
+ "version": "0.8.0-rc.1",
4
4
  "license": "MIT",
5
5
  "description": "Client runtime for managing messages and translations in a React project.",
6
6
  "main": "./dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "@formatjs/intl": "^2.10.1",
20
20
  "@intrnl/xxhash64": "^0.1.2",
21
21
  "intl-messageformat": "^10.5.11",
22
- "@discord/intl-ast": "0.8.0-rc.0"
22
+ "@discord/intl-ast": "0.8.0-rc.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@swc/cli": "^0.3.12",
@@ -116,7 +116,7 @@ export class IntlManager {
116
116
  * For static messages with no rich text and no dynamic placeholders, use this method to
117
117
  * immediately return the plain string value of the message in the current locale.
118
118
  */
119
- string<T extends TypedIntlMessageGetter<undefined>>(message: T): string {
119
+ string<T extends TypedIntlMessageGetter<{}>>(message: T): string {
120
120
  const resolved = message(this.currentLocale);
121
121
  if (resolved == null || resolved.ast.length === 0) return '';
122
122
 
package/src/types.d.ts CHANGED
@@ -49,11 +49,10 @@ export interface IntlMessageGetter extends IntlMessageGetterAdditions {
49
49
  /**
50
50
  * Getter function that retrieves a message that best matches the requested
51
51
  * locale. `FormatValues` represents either an object containing all of the
52
- * value types that are required to format the message, or `undefined` to
53
- * represent that there are no values required and the message is a plain
54
- * string.
52
+ * value types that are required to format the message, or `{}` to represent
53
+ * that there are no values required and the message is a plain string.
55
54
  */
56
- export interface TypedIntlMessageGetter<FormatValues extends object | undefined>
55
+ export interface TypedIntlMessageGetter<FormatValues extends object>
57
56
  extends IntlMessageGetterAdditions {
58
57
  // TODO: This is lossy and unfortunate that typing can't be propagated
59
58
  // to the returned message type, but doing so causes problems with
@@ -94,11 +93,7 @@ export interface TypedIntlMessageGetter<FormatValues extends object | undefined>
94
93
  * downstream will ensure that all format values are always checked for all
95
94
  * possible cases of the message.
96
95
  */
97
- __phantom: object extends FormatValues
98
- ? any
99
- : FormatValues extends undefined
100
- ? any
101
- : keyof FormatValues;
96
+ __phantom: object extends FormatValues ? any : {} extends FormatValues ? any : keyof FormatValues;
102
97
  }
103
98
 
104
99
  /**
@@ -145,7 +140,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
145
140
  * If T is a union of message types including both rich messages requiring
146
141
  * values _and_ plain string messages with no values, this type will still
147
142
  * properly resolve all of the required values, assuming that the getters for
148
- * the plain messages use the convention of passing `undefined` as the generic
143
+ * the plain messages use the convention of passing `{}` as the generic
149
144
  * argument, representing "no values should be passed for this message".
150
145
  *
151
146
  *
@@ -173,13 +168,13 @@ export type FormatValuesFor<T> =
173
168
  // be supplied, represented by the `never`. This prevents accidentally
174
169
  // passing an object, even an empty one, for those strings, and allows the
175
170
  // formatter to optimize a little more on each call.
176
- [T] extends [undefined]
171
+ [{}] extends [T]
177
172
  ? never
178
173
  : // The `never` condition needs to be repeated here, but this time _without_
179
174
  // the `[]` syntax, so that only the union elements with actual values are
180
175
  // included in the union. Without this, the `infer U` on the latter side
181
176
  // fails to resolve and the type just becomes `never`.
182
- UnionToIntersection<T extends undefined ? never : T>;
177
+ UnionToIntersection<{} extends T ? never : T>;
183
178
 
184
179
  /**
185
180
  * A template type for replaceable placeholder types to be defined by formatter
@@ -254,7 +249,7 @@ export type RequiredFormatValues<
254
249
  Values extends IntlMessageGetter,
255
250
  FunctionTypes extends FunctionTypeMap,
256
251
  > =
257
- IntlMessageGetterInnerType<Values> extends undefined
252
+ {} extends IntlMessageGetterInnerType<Values>
258
253
  ? {}
259
254
  : CheckStrictAny<
260
255
  IntlMessageGetterInnerType<Values>,