Skip to content

Make the translation function fully type-safe #1504

@karol-majewski

Description

@karol-majewski

🚀 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 microsoft/TypeScript#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 */
            ]
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions