I18next: Make the translation function fully type-safe

Created on 10 Sep 2020  路  6Comments  路  Source: i18next/i18next

馃殌 Feature Proposal

With the latest advancements in TypeScript, it's now possible to infer the correct paths from an object type. TypeScript 4.1 introduces recursive conditional types, and there is a PR open that will enable string type concatenation on the type level.

Motivation

18next.t accepts arbitrary strings. This allows silly human errors, since it's easy to make a typo.

Example

I put together a TypeScript Playground illustrating the improved definition.

Once https://github.com/microsoft/TypeScript/pull/40336 is merged and released, the improved definition can be put in a separate file loaded only for the ones using the minimum required TypeScript version. In package.json, it should say:

{
    "typesVersions": {
        ">=4.1.0-0": {
            "*": [
                /* Path to the new definition */
            ]
        }
    }
}
doc feature request typescript

Most helpful comment

up!?

All 6 comments

Very nice! Once the new TS is released, we can accept a PR for this. We may need to think about modifying our usage tests so that we can properly test it, we currently do not have any expect error notations being used.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This should be reopened, it is a must have feature and we already have a solution for it.

stalebot

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

up!?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

piehouserat picture piehouserat  路  4Comments

alakdam07 picture alakdam07  路  6Comments

LodewijkSioen picture LodewijkSioen  路  3Comments

Fr4ncx picture Fr4ncx  路  9Comments

obedm503 picture obedm503  路  3Comments