Skip to content

Commit

Permalink
⚡ improvement(typescript): Fix typings in components (#344) by @Demivan
Browse files Browse the repository at this point in the history
* Add failing test case

* Fix typings for component options
  • Loading branch information
Demivan authored and kazupon committed May 12, 2018
1 parent 56a57a1 commit 2402893
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ declare module 'vue/types/vue' {

declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
i18n?: VueI18n;
i18n?: {
messages?: VueI18n.LocaleMessages;
dateTimeFormats?: VueI18n.DateTimeFormats;
numberFormats?: VueI18n.NumberFormats;
};
}
}

Expand Down
43 changes: 43 additions & 0 deletions types/test/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Vue, { ComponentOptions } from 'vue';
import VueI18n from "../index";

// setup locale info for root Vue instance
const i18n = new VueI18n({
locale: 'ja',
messages: {
en: {
message: {
hello: 'hello world',
greeting: 'good morning'
}
},
ja: {
message: {
hello: 'こんにちは、世界',
greeting: 'おはようございます'
}
}
}
})

// Define component
const Component1 = {
template: `
<div class="container">
<p>Component1 locale messages: {{ $t("message.hello") }}</p>
<p>Fallback global locale messages: {{ $t("message.greeting") }}</p>
</div>`,
i18n: { // `i18n` option
messages: {
en: { message: { hello: 'hello component1' } },
ja: { message: { hello: 'こんにちは、component1' } }
}
}
}

new Vue({
i18n,
components: {
Component1
}
}).$mount('#app')

0 comments on commit 2402893

Please sign in to comment.