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

Commit

Permalink
Merge pull request #25 from panter/features/typescript
Browse files Browse the repository at this point in the history
feat(typescript): include typescript typings
  • Loading branch information
claudiocro authored May 29, 2018
2 parents f769be0 + 2797611 commit ac88d95
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"javascript.implicitProjectConfig.experimentalDecorators": true
}
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@
"scripts": {
"prepublish": "npm run build",
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules --debug && npm run build:lib",
"build":
"cross-env NODE_ENV=production webpack --progress --hide-modules --debug && npm run build:lib",
"build:lib": "rimraf ./lib && babel src --out-dir lib",
"lint": "eslint src/**.js",
"test": "npm run lint && npm run test:unit",
"test": "npm run lint && npm run test:unit && npm run test:types",
"test:unit": "cross-env BABEL_ENV=test karma start test/karma.conf.js",
"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",
"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",
"gh-pages-publish": "gh-pages -d gh-pages",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"coveralls": "cat ./test/coverage/lcov.info | coveralls"
"semantic-release":
"semantic-release pre && npm publish && semantic-release post",
"coveralls": "cat ./test/coverage/lcov.info | coveralls",
"test:types": "tsc -p typings"
},
"main": "./dist/vue-i18next.js",
"types": "typings/index.d.ts",
"peerDependencies": {
"i18next": ">= 6.0.1",
"vue": ">=2.0.0"
},
"devDependencies": {
"@types/i18next": "^8.4.3",
"babel-cli": "^6.24.1",
"babel-core": "^6.0.0",
"babel-eslint": "^6.1.2",
Expand Down Expand Up @@ -85,7 +91,9 @@
"semantic-release": "^6.3.6",
"sinon": "^2.1.0",
"sinon-chai": "^2.8.0",
"vue": "^2.2.0",
"typescript": "^2.8.3",
"vue": "^2.4.0",
"vue-class-component": "^6.2.0",
"vue-loader": "^10.0.0",
"vue-template-compiler": "^2.1.0",
"webpack": "^2.2.0",
Expand Down
43 changes: 43 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { i18n, TranslationFunction, TranslationOptions } from "i18next";
import Vue, { PluginFunction } from "vue";

declare class VueI18Next {
constructor(i18next: i18n, options: VueI18NextOptions);
i18next: i18n;
t: TranslationFunction;
resetVm: ({ }: { i18nLoadedAt: Date }) => void;
i18nLoadedAt: string;
onI18nChanged: () => void;

static install: PluginFunction<never>;
static version: string;
}

export interface VueI18NextOptions extends TranslationOptions {
bindI18n?: string;
bindStore?: string;
loadComponentNamespace?: boolean;
}

export interface VueI18NextComponentOptions {
namespaces?: string | Array<string>;
lng?: string;
keyPrefix?: string;
messages?: { [x: string]: {} };
}

declare module "vue/types/options" {
interface ComponentOptions<V extends Vue> {
i18n?: VueI18Next;
i18nOptions?: VueI18NextComponentOptions;
}
}

declare module "vue/types/vue" {
interface Vue {
readonly $i18n: VueI18Next;
$t: TranslationFunction;
}
}

export default VueI18Next;
42 changes: 42 additions & 0 deletions typings/test/vue-i18next-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Vue, { ComponentOptions } from "vue";
import * as i18next from "i18next";
import VueI18Next from "../index";
import { TranslationFunction } from "i18next";
import Component from "vue-class-component";

/**
* VueI18n.install
*/
Vue.use(VueI18Next);
VueI18Next.install(Vue);

VueI18Next.version; // $ExpectType string

i18next.init({
lng: "de",
resources: {}
});
const i18n = new VueI18Next(i18next, {});

const vm = new Vue({
i18n
});

vm.$i18n; // $ExpectType VueI18Next
vm.$i18n.i18next; // $ExpectType i18next
vm.$t; // $ExpectType TranslationFunction

@Component({
template: "<div><a v-on:click=\"changeLanguage('de')\">DE</a></div>"
})
class LanguageChangerComponent extends Vue {
changeLanguage(lang: string): void {
this.$i18n.i18next.changeLanguage(lang);
}
}

new LanguageChangerComponent().changeLanguage("de");

Vue.component("app", {
i18nOptions: { namespaces: "common" }
});
12 changes: 12 additions & 0 deletions typings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"strict": true,
"noEmit": true,
"noImplicitAny": true
},
"files": ["index.d.ts", "./test/vue-i18next-tests.ts"]
}
18 changes: 15 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
conventional-changelog "0.0.17"
github-url-from-git "^1.4.0"

"@types/i18next@^8.4.3":
version "8.4.3"
resolved "https://registry.yarnpkg.com/@types/i18next/-/i18next-8.4.3.tgz#9136a9551bf5bf7169aa9f3125c1743f1f8dd6de"

abbrev@1, [email protected]:
version "1.0.9"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
Expand Down Expand Up @@ -5962,6 +5966,10 @@ typedarray@^0.0.6, typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^2.8.3:
version "2.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170"

uglify-js@^2.6, uglify-js@^2.8.5:
version "2.8.23"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.23.tgz#8230dd9783371232d62a7821e2cf9a817270a8a0"
Expand Down Expand Up @@ -6121,6 +6129,10 @@ void-elements@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"

vue-class-component@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/vue-class-component/-/vue-class-component-6.2.0.tgz#7adb1daa9a868c75f30f97f33f4f1b94aee62089"

vue-hot-reload-api@^2.0.1:
version "2.1.0"
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.1.0.tgz#9ca58a6e0df9078554ce1708688b6578754d86de"
Expand Down Expand Up @@ -6159,9 +6171,9 @@ vue-template-es2015-compiler@^1.2.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.2.tgz#a0a6c50c941d2a4abda963f2f42c337ac450ee95"

vue@^2.2.0:
version "2.3.2"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.3.2.tgz#9e52aae3593480be235ff227557837e69f98203a"
vue@^2.4.0:
version "2.5.16"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085"

walk@^2.3.9:
version "2.3.9"
Expand Down

0 comments on commit ac88d95

Please sign in to comment.