Skip to content

Commit

Permalink
Fix typescript errors for 'next-intl'
Browse files Browse the repository at this point in the history
  • Loading branch information
barbarah committed Mar 5, 2024
1 parent e13ac62 commit cc46ecb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
9 changes: 4 additions & 5 deletions apps/researcher/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
* @type {import('next').NextConfig}
*/
// @ts-check

import NextIntlPlugin from 'next-intl/plugin';
import createNextIntlPlugin from 'next-intl/plugin';
import MDXPlugin from '@next/mdx';

const withNextIntl = NextIntlPlugin('./src/i18n.ts');
const withNextIntl = createNextIntlPlugin('./src/i18n.ts');
const withMDX = MDXPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@colonial-collections/ui'],
experimental: {
Expand Down
18 changes: 15 additions & 3 deletions apps/researcher/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import {notFound} from 'next/navigation';
import {getRequestConfig} from 'next-intl/server';
import {locales} from './navigation';
import {LocaleEnum} from '@/definitions';

export default getRequestConfig(async ({locale}) => ({
messages: (await import(`./messages/${locale}/messages.json`)).default,
}));
export default getRequestConfig(async ({locale}) => {
if (!locales.includes(locale as LocaleEnum)) notFound();

return {
messages: (
await (locale === 'en'
? // This will enable HMR for `en`
import('./messages/en/messages.json')
: import(`./messages/${locale}/messages.json`))
).default,
};
});
7 changes: 6 additions & 1 deletion apps/researcher/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"@/*": ["./src/*"]
}
},
"include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/lib", "src/types"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": ["cypress", "**/*.cy.tsx"]
}
1 change: 1 addition & 0 deletions packages/tsconfig/nextjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"incremental": true,
"module": "esnext",
"moduleResolution": "Bundler",
"declaration": false,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
Expand Down

0 comments on commit cc46ecb

Please sign in to comment.