-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add type exports to enable
declaration: true
in `tsconfig.jso…
…n` (#1509) Re: <#1014> Fix the type issues encountered when re-exporting types in a client application with `compilerOptions.declaration` set to `true`. This change addresses errors such as: > The inferred type of 'Link' cannot be named without a reference to '../node_modules/next-intl/dist/types/src/shared/types'. This is likely not portable. A type annotation is necessary.ts(2742) --------- Co-authored-by: Jan Amann <[email protected]>
- Loading branch information
Showing
8 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
examples/example-app-router-playground/src/type-portability-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
packages: | ||
- "packages/*" | ||
- "examples/*" | ||
- "docs" | ||
- 'packages/*' | ||
- 'examples/*' | ||
- 'docs' |