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

Export the backend options type #34

Merged
merged 2 commits into from
Dec 10, 2022
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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ const Backend = new Backend();
Backend.init(null, options);
```

## TypeScript

To properly type the backend options, you can import the `FsBackendOptions` interface and use it as a generic type parameter to the i18next's `init` method, e.g.:

```ts
import i18n from 'i18next'
import FsBackend, { FsBackendOptions } from 'i18next-fs-backend'

i18n
.use(FsBackend)
.init<FsBackendOptions>({
backend: {
// fs backend options
},

// other i18next options
})
```

# If set i18next initImmediate option to false it will load the files synchronously

```js
Expand Down
16 changes: 5 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type AddPathOption =
| string
| ((language: string, namespace: string) => string)

interface BackendOptions {
export interface FsBackendOptions {
/**
* path where resources get loaded from, or a function
* returning a path:
Expand All @@ -31,11 +31,11 @@ interface BackendOptions {
}

export default class I18NexFsBackend
implements BackendModule<BackendOptions>
implements BackendModule<FsBackendOptions>
{
static type: "backend";
constructor(services?: any, options?: BackendOptions);
init(services?: any, options?: BackendOptions): void;
constructor(services?: any, options?: FsBackendOptions);
init(services?: any, options?: FsBackendOptions): void;
read(language: string, namespace: string, callback: ReadCallback): void;
create?(
languages: string[],
Expand All @@ -45,11 +45,5 @@ export default class I18NexFsBackend
): void;
type: "backend";
services: any;
options: BackendOptions;
}

declare module "i18next" {
interface CustomPluginOptions {
backend?: BackendOptions;
}
options: FsBackendOptions;
}