Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add type exports to enable declaration: true in tsconfig.json #1509

Merged
merged 7 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
});
5 changes: 4 additions & 1 deletion examples/example-app-router-playground/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions packages/next-intl/src/navigation/react-client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion packages/next-intl/src/routing/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
6 changes: 5 additions & 1 deletion packages/next-intl/src/server/react-server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/use-intl/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
packages:
- "packages/*"
- "examples/*"
- "docs"
- 'packages/*'
- 'examples/*'
- 'docs'
Loading