Skip to content

Commit

Permalink
Add index.d.ts to improve IDE autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasr8 authored and ThiefMaster committed Jan 23, 2024
1 parent afd3466 commit 34debfe
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "0.5.0",
"description": "Provides gettext-enhanced React components, a babel plugin for extracting the strings and a script to compile translated strings to a format usable by the components.",
"main": "client/index.js",
"types": "client/index.d.ts",
"scripts": {
"build": "rm -rf client/ tools/ && babel src/ --out-dir ./ && chmod +x tools/cli.js",
"build": "rm -rf client/ tools/ && babel src/ --out-dir ./ && chmod +x tools/cli.js && cp src/client/index.d.ts client/index.d.ts",
"prepare": "npm run build",
"eslint": "eslint --ext .js --ext .jsx src/ tests/ test-data/",
"update-test-data": "./update-test-data.sh",
Expand Down
85 changes: 85 additions & 0 deletions src/client/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as React from 'react';

export interface ParamProps {
/** Parameter name */
name: string;

/** Value to render */
value?: any;

/** A React element to wrap the parameter value/children */
wrapper?: React.ReactElement;
children?: React.ReactNode;
}

export const Param: React.FC<ParamProps>;

export interface SingularProps {
children: React.ReactNode;
}

export const Singular: React.FC<SingularProps>;

export interface PluralProps {
children: React.ReactNode;
}

export const Plural: React.FC<PluralProps>;

export interface TranslateProps {
/** Message context */
context?: string;

/** An element type to render as */
as?: React.ComponentType;
children: React.ReactNode;
}

export const Translate: React.FC<TranslateProps> & {
/**
* Translate a string
* @param string The message to translate
* @param args Optional context and parameters
* @returns The translated string
*/
string: (string: string, ...args: any[]) => string;
};

export interface PluralTranslateProps {
/** Determines whether the singular or plural will be used */
count: number;

/** Message context */
context?: string;

/** An element type to render as */
as?: React.ComponentType;
children: React.ReactNode;
}

export const PluralTranslate: React.FC<PluralTranslateProps> & {
/**
* Translate a string including pluralization
* @param singular The singular form of the message
* @param plural The plural form of the message
* @param count Determines whether the singular or plural will be used
* @param args Optional context and parameters
* @returns The translated string
*/
string: (singular: string, plural: string, count: number, ...args: any[]) => string;
};

export interface Config {
gettext: (msg: string) => string;
ngettext: (msg: string, msgpl: string, n: number) => string;
pgettext?: (ctx: string, msg: string) => string;
npgettext?: (ctx: string, msg: string, msgpl: string, n: number) => string;
options?: any;
}

export interface Components {
Translate: typeof Translate;
PluralTranslate: typeof PluralTranslate;
}

export function makeComponents(config: Config): Components;

0 comments on commit 34debfe

Please sign in to comment.