Skip to content

Typesafety: prevent usage of non existing keys #2307

@ThomasKientz

Description

@ThomasKientz

Clear and concise description of the problem

We can setup autocompletion with typescript but we can't make typescript throws an error if we try to translate a non existing key.

import type fr from "../i18n/fr.json";
const { t } = useI18n<{ message: typeof fr }>();

const translation = t("key.non_existing"); // doesn't throw a typescript error

Suggested solution

Update the types to make typescript throws an error.

Alternative

Adding <""> makes typescript throws:

import type fr from "../i18n/fr.json";
const { t } = useI18n<{ message: typeof fr }>();

const translation = t<"">("key.non_existing"); // ts throws error as exepected

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions