Skip to content

Feat: Add TypeScript support for globally injected i18n properties #2200

@A-kirami

Description

@A-kirami

Clear and concise description of the problem

When using Vue I18n with TypeScript, while the injected properties like $t work correctly at runtime, TypeScript shows an error "Cannot find name $t" because these globally injected properties lack proper type definitions.

This creates a poor developer experience in TypeScript projects where we need to either:

  1. Ignore the TypeScript errors
  2. Manually declare types for these globals

Suggested solution

We could provide TypeScript type definitions for all globally injected properties ($i18n, $t, $rt, $d, $n, $tm) similar to how other libraries handle this.

A possible implementation would be to:

  1. Create a type declaration file that defines all the injected i18n properties
  2. Make it available via <reference types="vue-i18n/global" />

This feature would significantly improve the developer experience for TypeScript users while maintaining backward compatibility.

Alternative

  1. Explicitly importing and using the Composer API in every component (but this loses the convenience of implicit injection)
  2. Manually extending ComponentCustomProperties in each project (not ideal as it requires manual setup)

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