Skip to content
5 changes: 5 additions & 0 deletions static/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module.exports = {
preset: "ts-jest/presets/js-with-ts",
globals: {
google: {},
"ts-jest": {
tsconfig: {
module: "commonjs",
},
},
},
testEnvironment: "jest-environment-jsdom",
};
4 changes: 2 additions & 2 deletions static/js/i18n/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let intl: IntlShape = createIntl({ locale: "en", messages: {} }, intlCache);
*/
function loadLocaleData(
locale: string,
modules: Promise<Record<any, any>>[]
modules: (Promise<Record<string, any>> | Record<string, any>)[]
): Promise<void> {
const allMessages = {};
// If no i18n modules are provided, just set the locale and return.
Expand All @@ -54,7 +54,7 @@ function loadLocaleData(
return Promise.all(modules)
.then((messages) => {
for (const msg of messages) {
Object.assign(allMessages, msg.default);
Object.assign(allMessages, msg.default || msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change correctly handles modules loaded via require, the calls to loadLocaleData throughout the codebase now pass synchronous require() results, which are not Promises. This violates the function's type signature for the modules parameter (Promise<Record<any, any>>[]).

To maintain type safety, please update the signature of loadLocaleData to reflect its new usage. For example:

function loadLocaleData(
  locale: string,
  modules: (Promise<Record<any, any>> | Record<any, any>)[]
): Promise<void> {

This will ensure the function signature accurately represents that it can handle both promises (from dynamic import()) and direct objects (from require()).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

}
intl = createIntl({ locale, messages: allMessages }, intlCache);
})
Expand Down
1 change: 0 additions & 1 deletion static/js/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import axios from "axios";
import _ from "lodash";
import { URLSearchParams } from "url";

import { AutoCompleteResult } from "../components/nl_search_bar/auto_complete_input";
import { Theme } from "../theme/types";
Expand Down
9 changes: 7 additions & 2 deletions static/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"module": "CommonJS",
"target": "es6",
"module": "esnext",
"target": "es2021",
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react",
"allowJs": true,
Expand All @@ -19,6 +19,11 @@
"moduleResolution": "node",
"experimentalDecorators": true
},
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
},
"exclude": [
"node_modules",
"./**/*.test.ts",
Expand Down
6 changes: 6 additions & 0 deletions static/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ const config = {
},
],
},
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
],
},
plugins: [
Expand Down
Loading