xiCO2k / laravel-vue-i18n

Allows to connect your `Laravel` Framework translation files with `Vue`.
MIT License
621 stars 51 forks source link

Mixins are not available when using TypeScript #111

Closed daniser closed 1 year ago

daniser commented 1 year ago

I can't use $t and $tChoice mixins, TypeScript doesn't compile:

error TS2339: Property '$t' does not exist on type '{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ team?: OperatorTeam | undefined; operators: Operator[]; ticketCategories: TicketCategory[]; errors: Record<...>; }>>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>; .....'.

66                                 {{ $t("main.save") }}
                                      ~~
xiCO2k commented 1 year ago

Hey @daniser can you create a repo with that exact issue?

Thanks.

daniser commented 1 year ago

@xiCO2k https://github.com/daniser/i18n-example Without vue-tsc it works well.

xiCO2k commented 1 year ago

Great Thanks

jezzdk commented 1 year ago

@daniser This worked for me:

  1. create resources/js/types/global.d.ts (if it's not there already)
  2. make sure the following is in the file:
    
    import { trans } from 'laravel-vue-i18n';

declare module 'vue' { interface ComponentCustomProperties { $t: typeof trans; } }

3. make sure the file is included in tsconfig.json:

{ ... "include": ["resources/js/*/.d.ts", ...] ... }

xiCO2k commented 1 year ago

If anyone want to help, making a PR to solve this, I would love to review it.