Skip to content
This repository was archived by the owner on May 19, 2022. It is now read-only.

Commit ac88d95

Browse files
authored
Merge pull request #25 from panter/features/typescript
feat(typescript): include typescript typings
2 parents f769be0 + 2797611 commit ac88d95

File tree

6 files changed

+129
-9
lines changed

6 files changed

+129
-9
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"javascript.implicitProjectConfig.experimentalDecorators": true
3+
}

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,28 @@
2121
"scripts": {
2222
"prepublish": "npm run build",
2323
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
24-
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules --debug && npm run build:lib",
24+
"build":
25+
"cross-env NODE_ENV=production webpack --progress --hide-modules --debug && npm run build:lib",
2526
"build:lib": "rimraf ./lib && babel src --out-dir lib",
2627
"lint": "eslint src/**.js",
27-
"test": "npm run lint && npm run test:unit",
28+
"test": "npm run lint && npm run test:unit && npm run test:types",
2829
"test:unit": "cross-env BABEL_ENV=test karma start test/karma.conf.js",
29-
"gh-pages": "npm run build && rimraf ./gh-pages && mkdirp ./gh-pages/examples mkdirp ./gh-pages/dist && ncp ./examples ./gh-pages/examples && ncp ./dist ./gh-pages/dist",
30+
"gh-pages":
31+
"npm run build && rimraf ./gh-pages && mkdirp ./gh-pages/examples mkdirp ./gh-pages/dist && ncp ./examples ./gh-pages/examples && ncp ./dist ./gh-pages/dist",
3032
"gh-pages-publish": "gh-pages -d gh-pages",
31-
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
32-
"coveralls": "cat ./test/coverage/lcov.info | coveralls"
33+
"semantic-release":
34+
"semantic-release pre && npm publish && semantic-release post",
35+
"coveralls": "cat ./test/coverage/lcov.info | coveralls",
36+
"test:types": "tsc -p typings"
3337
},
3438
"main": "./dist/vue-i18next.js",
39+
"types": "typings/index.d.ts",
3540
"peerDependencies": {
3641
"i18next": ">= 6.0.1",
3742
"vue": ">=2.0.0"
3843
},
3944
"devDependencies": {
45+
"@types/i18next": "^8.4.3",
4046
"babel-cli": "^6.24.1",
4147
"babel-core": "^6.0.0",
4248
"babel-eslint": "^6.1.2",
@@ -85,7 +91,9 @@
8591
"semantic-release": "^6.3.6",
8692
"sinon": "^2.1.0",
8793
"sinon-chai": "^2.8.0",
88-
"vue": "^2.2.0",
94+
"typescript": "^2.8.3",
95+
"vue": "^2.4.0",
96+
"vue-class-component": "^6.2.0",
8997
"vue-loader": "^10.0.0",
9098
"vue-template-compiler": "^2.1.0",
9199
"webpack": "^2.2.0",

typings/index.d.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { i18n, TranslationFunction, TranslationOptions } from "i18next";
2+
import Vue, { PluginFunction } from "vue";
3+
4+
declare class VueI18Next {
5+
constructor(i18next: i18n, options: VueI18NextOptions);
6+
i18next: i18n;
7+
t: TranslationFunction;
8+
resetVm: ({ }: { i18nLoadedAt: Date }) => void;
9+
i18nLoadedAt: string;
10+
onI18nChanged: () => void;
11+
12+
static install: PluginFunction<never>;
13+
static version: string;
14+
}
15+
16+
export interface VueI18NextOptions extends TranslationOptions {
17+
bindI18n?: string;
18+
bindStore?: string;
19+
loadComponentNamespace?: boolean;
20+
}
21+
22+
export interface VueI18NextComponentOptions {
23+
namespaces?: string | Array<string>;
24+
lng?: string;
25+
keyPrefix?: string;
26+
messages?: { [x: string]: {} };
27+
}
28+
29+
declare module "vue/types/options" {
30+
interface ComponentOptions<V extends Vue> {
31+
i18n?: VueI18Next;
32+
i18nOptions?: VueI18NextComponentOptions;
33+
}
34+
}
35+
36+
declare module "vue/types/vue" {
37+
interface Vue {
38+
readonly $i18n: VueI18Next;
39+
$t: TranslationFunction;
40+
}
41+
}
42+
43+
export default VueI18Next;

typings/test/vue-i18next-tests.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Vue, { ComponentOptions } from "vue";
2+
import * as i18next from "i18next";
3+
import VueI18Next from "../index";
4+
import { TranslationFunction } from "i18next";
5+
import Component from "vue-class-component";
6+
7+
/**
8+
* VueI18n.install
9+
*/
10+
Vue.use(VueI18Next);
11+
VueI18Next.install(Vue);
12+
13+
VueI18Next.version; // $ExpectType string
14+
15+
i18next.init({
16+
lng: "de",
17+
resources: {}
18+
});
19+
const i18n = new VueI18Next(i18next, {});
20+
21+
const vm = new Vue({
22+
i18n
23+
});
24+
25+
vm.$i18n; // $ExpectType VueI18Next
26+
vm.$i18n.i18next; // $ExpectType i18next
27+
vm.$t; // $ExpectType TranslationFunction
28+
29+
@Component({
30+
template: "<div><a v-on:click=\"changeLanguage('de')\">DE</a></div>"
31+
})
32+
class LanguageChangerComponent extends Vue {
33+
changeLanguage(lang: string): void {
34+
this.$i18n.i18next.changeLanguage(lang);
35+
}
36+
}
37+
38+
new LanguageChangerComponent().changeLanguage("de");
39+
40+
Vue.component("app", {
41+
i18nOptions: { namespaces: "common" }
42+
});

typings/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"moduleResolution": "node",
5+
"allowSyntheticDefaultImports": true,
6+
"experimentalDecorators": true,
7+
"strict": true,
8+
"noEmit": true,
9+
"noImplicitAny": true
10+
},
11+
"files": ["index.d.ts", "./test/vue-i18next-tests.ts"]
12+
}

yarn.lock

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
conventional-changelog "0.0.17"
3636
github-url-from-git "^1.4.0"
3737

38+
"@types/i18next@^8.4.3":
39+
version "8.4.3"
40+
resolved "https://registry.yarnpkg.com/@types/i18next/-/i18next-8.4.3.tgz#9136a9551bf5bf7169aa9f3125c1743f1f8dd6de"
41+
3842
abbrev@1, abbrev@1.0.x:
3943
version "1.0.9"
4044
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
@@ -5962,6 +5966,10 @@ typedarray@^0.0.6, typedarray@~0.0.5:
59625966
version "0.0.6"
59635967
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
59645968

5969+
typescript@^2.8.3:
5970+
version "2.8.3"
5971+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170"
5972+
59655973
uglify-js@^2.6, uglify-js@^2.8.5:
59665974
version "2.8.23"
59675975
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.23.tgz#8230dd9783371232d62a7821e2cf9a817270a8a0"
@@ -6121,6 +6129,10 @@ void-elements@^2.0.0:
61216129
version "2.0.1"
61226130
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"
61236131

6132+
vue-class-component@^6.2.0:
6133+
version "6.2.0"
6134+
resolved "https://registry.yarnpkg.com/vue-class-component/-/vue-class-component-6.2.0.tgz#7adb1daa9a868c75f30f97f33f4f1b94aee62089"
6135+
61246136
vue-hot-reload-api@^2.0.1:
61256137
version "2.1.0"
61266138
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.1.0.tgz#9ca58a6e0df9078554ce1708688b6578754d86de"
@@ -6159,9 +6171,9 @@ vue-template-es2015-compiler@^1.2.2:
61596171
version "1.5.2"
61606172
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.2.tgz#a0a6c50c941d2a4abda963f2f42c337ac450ee95"
61616173

6162-
vue@^2.2.0:
6163-
version "2.3.2"
6164-
resolved "https://registry.yarnpkg.com/vue/-/vue-2.3.2.tgz#9e52aae3593480be235ff227557837e69f98203a"
6174+
vue@^2.4.0:
6175+
version "2.5.16"
6176+
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085"
61656177

61666178
walk@^2.3.9:
61676179
version "2.3.9"

0 commit comments

Comments
 (0)