diff --git a/examples/example-app-router-playground/src/type-portability-test.ts b/examples/example-app-router-playground/src/type-portability-test.ts new file mode 100644 index 000000000..18facf87d --- /dev/null +++ b/examples/example-app-router-playground/src/type-portability-test.ts @@ -0,0 +1,69 @@ +// Ensure that exported types function as expected for library creators. +// +// Most functionality is already tested through usage in this application. +// This file includes exports for any that are not yet covered. + +import { + createFormatter, + createTranslator, + initializeConfig, + useFormatter, + useLocale, + useMessages, + useNow, + useTimeZone, + useTranslations +} from 'next-intl'; +import createNextIntlPlugin from 'next-intl/plugin'; +import { + getFormatter, + getLocale, + getMessages, + getNow, + getTimeZone, + getTranslations +} from 'next-intl/server'; + +export function useExports() { + const messages = useMessages(); + const now = useNow(); + const locale = useLocale(); + const timezone = useTimeZone(); + const formatter = useFormatter(); + const translations = useTranslations(); + + return { + messages, + now, + locale, + timezone, + formatter, + translations + }; +} + +export async function asyncApis() { + const messages = await getMessages(); + const now = await getNow(); + const locale = await getLocale(); + const timezone = await getTimeZone(); + const formatter = await getFormatter(); + const translations = await getTranslations(); + + return { + messages, + now, + locale, + timezone, + formatter, + translations + }; +} + +export const withNextIntl = createNextIntlPlugin(); +export const config = initializeConfig({locale: 'en'}); +export const translator = createTranslator({locale: 'en'}); +export const formatter = createFormatter({ + locale: 'en', + now: new Date(2022, 10, 6, 20, 20, 0, 0) +}); diff --git a/examples/example-app-router-playground/tsconfig.json b/examples/example-app-router-playground/tsconfig.json index 8d6bca754..710349cbe 100644 --- a/examples/example-app-router-playground/tsconfig.json +++ b/examples/example-app-router-playground/tsconfig.json @@ -20,7 +20,10 @@ ], "paths": { "@/*": ["./src/*"] - } + }, + + // See https://github.com/amannn/next-intl/pull/1509 + "declaration": true }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "exclude": ["node_modules"] diff --git a/packages/next-intl/src/navigation/react-client/index.tsx b/packages/next-intl/src/navigation/react-client/index.tsx index c4183b53b..7d0372b79 100644 --- a/packages/next-intl/src/navigation/react-client/index.tsx +++ b/packages/next-intl/src/navigation/react-client/index.tsx @@ -2,6 +2,8 @@ export {default as createSharedPathnamesNavigation} from './createSharedPathname export {default as createLocalizedPathnamesNavigation} from './createLocalizedPathnamesNavigation'; export {default as createNavigation} from './createNavigation'; +export type {QueryParams} from '../shared/utils'; + import type { Locales, Pathnames as PathnamesDeprecatedExport diff --git a/packages/next-intl/src/routing/index.tsx b/packages/next-intl/src/routing/index.tsx index d0832e45d..ac10d4159 100644 --- a/packages/next-intl/src/routing/index.tsx +++ b/packages/next-intl/src/routing/index.tsx @@ -1,2 +1,8 @@ -export type {Pathnames, LocalePrefix, DomainsConfig} from './types'; +export type { + Pathnames, + DomainsConfig, + LocalePrefix, + LocalePrefixMode +} from './types'; +export type {RoutingConfig} from './config'; export {default as defineRouting} from './defineRouting'; diff --git a/packages/next-intl/src/server/react-server/index.tsx b/packages/next-intl/src/server/react-server/index.tsx index 258707b90..3b368f52e 100644 --- a/packages/next-intl/src/server/react-server/index.tsx +++ b/packages/next-intl/src/server/react-server/index.tsx @@ -2,7 +2,11 @@ * Server-only APIs available via `next-intl/server`. */ -export {default as getRequestConfig} from './getRequestConfig'; +export { + default as getRequestConfig, + type GetRequestConfigParams, + type RequestConfig +} from './getRequestConfig'; export {default as getFormatter} from './getFormatter'; export {default as getNow} from './getNow'; export {default as getTimeZone} from './getTimeZone'; diff --git a/packages/use-intl/src/core/index.tsx b/packages/use-intl/src/core/index.tsx index cfc3cc0e4..a298caf02 100644 --- a/packages/use-intl/src/core/index.tsx +++ b/packages/use-intl/src/core/index.tsx @@ -8,6 +8,8 @@ export type {default as Formats} from './Formats'; export type {default as IntlConfig} from './IntlConfig'; export type {default as DateTimeFormatOptions} from './DateTimeFormatOptions'; export type {default as NumberFormatOptions} from './NumberFormatOptions'; +export type {default as RelativeTimeFormatOptions} from './RelativeTimeFormatOptions'; +export type {default as Timezone} from './TimeZone'; export {default as IntlError, IntlErrorCode} from './IntlError'; export {default as createTranslator} from './createTranslator'; export {default as createFormatter} from './createFormatter'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 253e2107e..56497d467 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22914,7 +22914,7 @@ snapshots: debug: 4.3.7(supports-color@6.1.0) enhanced-resolve: 5.17.1 eslint: 9.13.0(jiti@2.3.3) - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-plugin-import@2.31.0)(eslint@9.13.0(jiti@2.3.3)))(eslint@9.13.0(jiti@2.3.3)) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.13.0(jiti@2.3.3)) fast-glob: 3.3.2 get-tsconfig: 4.7.5 is-bun-module: 1.2.1 @@ -22933,7 +22933,7 @@ snapshots: debug: 4.3.7(supports-color@6.1.0) enhanced-resolve: 5.17.1 eslint: 9.13.0(jiti@2.3.3) - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-plugin-import@2.31.0)(eslint@9.13.0(jiti@2.3.3)))(eslint@9.13.0(jiti@2.3.3)) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.13.0(jiti@2.3.3)) fast-glob: 3.3.2 get-tsconfig: 4.7.5 is-bun-module: 1.2.1 @@ -22946,7 +22946,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-plugin-import@2.31.0)(eslint@9.13.0(jiti@2.3.3)))(eslint@9.13.0(jiti@2.3.3)): + eslint-module-utils@2.12.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.13.0(jiti@2.3.3)): dependencies: debug: 3.2.7(supports-color@6.1.0) optionalDependencies: @@ -22957,7 +22957,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-plugin-import@2.31.0)(eslint@9.13.0(jiti@2.3.3)))(eslint@9.13.0(jiti@2.3.3)): + eslint-module-utils@2.12.0(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.13.0(jiti@2.3.3)): dependencies: debug: 3.2.7(supports-color@6.1.0) optionalDependencies: @@ -22985,7 +22985,7 @@ snapshots: doctrine: 2.1.0 eslint: 9.13.0(jiti@2.3.3) eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-plugin-import@2.31.0)(eslint@9.13.0(jiti@2.3.3)))(eslint@9.13.0(jiti@2.3.3)) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.11.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.13.0(jiti@2.3.3)) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -23014,7 +23014,7 @@ snapshots: doctrine: 2.1.0 eslint: 9.13.0(jiti@2.3.3) eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-plugin-import@2.31.0)(eslint@9.13.0(jiti@2.3.3)))(eslint@9.13.0(jiti@2.3.3)) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.9.0(eslint@9.13.0(jiti@2.3.3))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.3)(eslint@9.13.0(jiti@2.3.3)) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4bfe0befb..dd8cb5185 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,4 +1,4 @@ packages: - - "packages/*" - - "examples/*" - - "docs" + - 'packages/*' + - 'examples/*' + - 'docs'