-
-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resource Keys completion does not work with global messages and $t #1124
Labels
❗ p4-important
Priority 4: bugs that violate documented behavior, or significantly impact perf
Type: Improvement
Includes backwards-compatible fixes
typescript
Comments
kazupon
added
Type: Improvement
Includes backwards-compatible fixes
and removed
Status: Review Needed
Request for review comments
labels
Aug 19, 2022
kazupon
added
❗ p4-important
Priority 4: bugs that violate documented behavior, or significantly impact perf
typescript
labels
Nov 15, 2022
— with
Volta.net
4 tasks
Any updates on this @kazupon? Would really help the DX in nuxt-i18n :) |
Here is workaround to fix type autocomplete locally // typing.d.ts
interface ITranslations {
form: {
labels: {
email: string;
password: string;
};
errors: {
email: string;
minLength: string;
required: string;
};
};
signIn: {
heading: string;
submit: string;
};
}
type Primitive = string | number | bigint | boolean | undefined | symbol;
export type PropertyStringPath<T, Prefix = ''> = {
[K in keyof T]: T[K] extends Primitive | Array<unknown>
? `${string & Prefix}${string & K}`
: `${string & Prefix}${string & K}` | PropertyStringPath<T[K], `${string & Prefix}${string & K}.`>;
}[keyof T];
declare module 'vue-i18n' {
export interface DefineLocaleMessage extends ITranslations {}
}
declare module '@vue/runtime-core' {
import type { TranslateResult } from 'vue-i18n';
export interface ComponentCustomProperties {
$t<Key extends PropertyStringPath<ITranslations>>(key: Key): TranslateResult;
}
} |
Thanks for that, I ended up doing exactly that just with a little bit less TS magic: // types.d.ts
import {
DefineLocaleMessage,
} from 'vue-i18n'
import type enUS from './locales/en-US.json'
type MessageSchema = typeof enUS
declare module 'vue-i18n' {
export interface DefineLocaleMessage extends MessageSchema {}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
❗ p4-important
Priority 4: bugs that violate documented behavior, or significantly impact perf
Type: Improvement
Includes backwards-compatible fixes
typescript
Reporting a bug?
When using global definitions and $t, key completion (and type checking) does not work.
Here is the declaration file I use:
I set it up like this:
Then in a component I try to type in but nothing appears:
Expected behavior
Resource completion should work if I understood the doc correctly.
Should type checking work too?
Reproduction
Enough information.
System Info
Screenshot
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: