Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: @lingui/macro types for global environments (#973)
- Loading branch information
Showing
4 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
declare module '@lingui/macro' { | ||
import type { MessageDescriptor } from "@lingui/core" | ||
|
||
export type BasicType = { | ||
id?: string | ||
comment?: string | ||
} | ||
|
||
export function t( | ||
literals: TemplateStringsArray | MessageDescriptor, | ||
...placeholders: any[] | ||
): string | ||
|
||
export type UnderscoreDigit<T = string> = { [digit: string]: T } | ||
export type ChoiceOptions<T = string> = { | ||
offset?: number | ||
zero?: T | ||
one?: T | ||
few?: T | ||
many?: T | ||
other?: T | ||
} & UnderscoreDigit<T> | ||
|
||
export function plural(arg: number | string, options: ChoiceOptions & BasicType): string | ||
export function selectOrdinal( | ||
arg: number | string, | ||
options: ChoiceOptions & BasicType | ||
): string | ||
export function select(arg: string, choices: Record<string, string> & BasicType): string | ||
export function defineMessages<M extends Record<string, MessageDescriptor>>( | ||
messages: M | ||
): M | ||
export function defineMessage(descriptor: MessageDescriptor): MessageDescriptor | ||
|
||
export type ChoiceProps = { | ||
value?: string | number | ||
} & ChoiceOptions<string> | ||
|
||
/** | ||
* The types should be changed after this PR is merged | ||
* https://github.com/Microsoft/TypeScript/pull/26797 | ||
* | ||
* then we should be able to specify that key of values is same type as value. | ||
* We would be able to remove separate type Values = {...} definition | ||
* eg. | ||
* type SelectProps<Values> = { | ||
* value?: Values | ||
* [key: Values]: string | ||
* } | ||
* | ||
*/ | ||
type Values = { [key: string]: string } | ||
|
||
export type SelectProps = { | ||
value: string | ||
other: any | ||
} & Values | ||
|
||
export const Trans: any | ||
export const Plural: any | ||
export const Select: any | ||
export const SelectOrdinal: any | ||
} |
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"LICENSE", | ||
"README.md", | ||
"*.js", | ||
"global.d.ts", | ||
"index.d.ts" | ||
], | ||
"dependencies": { | ||
|
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
92a5ce7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: