Browse Source

Update typings (#334)

* fix logger.d.ts

* adapt Vue 2.0 typings

* add npm script to test typings

* ActionInjectee -> ActionContext
katashin 8 năm trước cách đây
mục cha
commit
4a6dee4a83

+ 1 - 1
dist/logger.d.ts

@@ -3,7 +3,7 @@
  * This file must be put alongside the JavaScript file of the logger.
  * This file must be put alongside the JavaScript file of the logger.
  */
  */
 
 
-import { Payload, Plugin } from './types/index'
+import { Payload, Plugin } from "../types/index";
 
 
 export interface LoggerOption<S> {
 export interface LoggerOption<S> {
   collapsed?: boolean;
   collapsed?: boolean;

+ 4 - 2
package.json

@@ -17,9 +17,10 @@
     "build": "npm run build:main && npm run build:logger",
     "build": "npm run build:main && npm run build:logger",
     "build:main": "rollup -c build/rollup.config.js && uglifyjs dist/vuex.js -cm --comments -o dist/vuex.min.js",
     "build:main": "rollup -c build/rollup.config.js && uglifyjs dist/vuex.js -cm --comments -o dist/vuex.min.js",
     "build:logger": "rollup -c build/rollup.logger.config.js",
     "build:logger": "rollup -c build/rollup.logger.config.js",
-    "test": "eslint src && npm run test:unit && npm run test:e2e",
+    "test": "eslint src && npm run test:types && npm run test:unit && npm run test:e2e",
     "test:unit": "rollup -c build/rollup.config.js && jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
     "test:unit": "rollup -c build/rollup.config.js && jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
     "test:e2e": "node test/e2e/runner.js",
     "test:e2e": "node test/e2e/runner.js",
+    "test:types": "tsc -p types/test",
     "release": "bash build/release.sh",
     "release": "bash build/release.sh",
     "docs": "cd docs && gitbook serve",
     "docs": "cd docs && gitbook serve",
     "docs:deploy": "cd docs && ./deploy.sh"
     "docs:deploy": "cd docs && ./deploy.sh"
@@ -59,8 +60,9 @@
     "rollup-watch": "^2.5.0",
     "rollup-watch": "^2.5.0",
     "selenium-server": "^2.53.1",
     "selenium-server": "^2.53.1",
     "todomvc-app-css": "^2.0.3",
     "todomvc-app-css": "^2.0.3",
+    "typescript": "^2.0.3",
     "uglify-js": "^2.6.2",
     "uglify-js": "^2.6.2",
-    "vue": "^2.0.0-beta.5",
+    "vue": "^2.0.0-rc.7",
     "vue-loader": "^9.0.3",
     "vue-loader": "^9.0.3",
     "webpack": "^1.13.2",
     "webpack": "^1.13.2",
     "webpack-dev-middleware": "^1.6.1",
     "webpack-dev-middleware": "^1.6.1",

+ 3 - 1
types/helpers.d.ts

@@ -1,9 +1,11 @@
+import Vue = require("vue");
+
 type Dictionary<T> = { [key: string]: T };
 type Dictionary<T> = { [key: string]: T };
 
 
 export function mapState (map: string[]): Dictionary<() => any>;
 export function mapState (map: string[]): Dictionary<() => any>;
 export function mapState (map: Dictionary<string>): Dictionary<() => any>;
 export function mapState (map: Dictionary<string>): Dictionary<() => any>;
 export function mapState <S>(
 export function mapState <S>(
-  map: Dictionary<(this: vuejs.Vue, state: S, getters: any) => any>
+  map: Dictionary<(this: typeof Vue, state: S, getters: any) => any>
 ): Dictionary<() => any>;
 ): Dictionary<() => any>;
 
 
 type MutationMethod = (...args: any[]) => void;
 type MutationMethod = (...args: any[]) => void;

+ 8 - 9
types/index.d.ts

@@ -1,3 +1,7 @@
+import _Vue = require("vue");
+import { WatchOptions } from "vue";
+
+// augment typings of Vue.js
 import "./vue";
 import "./vue";
 
 
 export * from "./helpers";
 export * from "./helpers";
@@ -14,7 +18,7 @@ export declare class Store<S> {
   commit: Commit;
   commit: Commit;
 
 
   subscribe<P extends Payload>(fn: (mutation: P, state: S) => any): () => void;
   subscribe<P extends Payload>(fn: (mutation: P, state: S) => any): () => void;
-  watch<T>(getter: (state: S) => T, cb: (value: T) => void, options?: WatchOption): void;
+  watch<T>(getter: (state: S) => T, cb: (value: T) => void, options?: WatchOptions): void;
 
 
   registerModule<T>(path: string, module: Module<T, S>): void;
   registerModule<T>(path: string, module: Module<T, S>): void;
   registerModule<T>(path: string[], module: Module<T, S>): void;
   registerModule<T>(path: string[], module: Module<T, S>): void;
@@ -30,7 +34,7 @@ export declare class Store<S> {
   }): void;
   }): void;
 }
 }
 
 
-export declare function install(Vue: vuejs.VueStatic): void;
+export declare function install(Vue: typeof _Vue): void;
 
 
 export interface Dispatch {
 export interface Dispatch {
   (type: string, payload?: any): Promise<any[]>;
   (type: string, payload?: any): Promise<any[]>;
@@ -42,7 +46,7 @@ export interface Commit {
   <P extends Payload>(payloadWithType: P, options?: CommitOptions): void;
   <P extends Payload>(payloadWithType: P, options?: CommitOptions): void;
 }
 }
 
 
-export interface ActionInjectee<S, R> {
+export interface ActionContext<S, R> {
   dispatch: Dispatch;
   dispatch: Dispatch;
   commit: Commit;
   commit: Commit;
   state: S;
   state: S;
@@ -69,7 +73,7 @@ export interface StoreOptions<S> {
 }
 }
 
 
 export type Getter<S, R> = (state: S, getters: any, rootState: R) => any;
 export type Getter<S, R> = (state: S, getters: any, rootState: R) => any;
-export type Action<S, R> = (injectee: ActionInjectee<S, R>, payload: any) => any;
+export type Action<S, R> = (injectee: ActionContext<S, R>, payload: any) => any;
 export type Mutation<S> = (state: S, payload: any) => any;
 export type Mutation<S> = (state: S, payload: any) => any;
 export type Plugin<S> = (store: Store<S>) => any;
 export type Plugin<S> = (store: Store<S>) => any;
 
 
@@ -96,8 +100,3 @@ export interface MutationTree<S> {
 export interface ModuleTree<R> {
 export interface ModuleTree<R> {
   [key: string]: Module<any, R>;
   [key: string]: Module<any, R>;
 }
 }
-
-export interface WatchOption {
-  deep?: boolean;
-  immediate?: boolean;
-}

+ 1 - 1
types/test/helpers.ts

@@ -1,4 +1,4 @@
-import * as Vue from "vue";
+import Vue = require("vue");
 
 
 import {
 import {
   mapState,
   mapState,

+ 4 - 4
types/test/index.ts

@@ -1,6 +1,6 @@
-import * as Vue from "vue";
+import Vue = require("vue");
 import * as Vuex from "../index";
 import * as Vuex from "../index";
-import createLogger from "../../logger";
+import createLogger from "../../dist/logger";
 
 
 Vue.use(Vuex);
 Vue.use(Vuex);
 
 
@@ -80,7 +80,7 @@ namespace NestedModules {
     };
     };
   }
   }
 
 
-  type ActionStore = Vuex.ActionInjectee<{ value: number }, RootState>
+  type ActionStore = Vuex.ActionContext<{ value: number }, RootState>
 
 
   const module = {
   const module = {
     state: {
     state: {
@@ -160,7 +160,7 @@ namespace HotUpdate {
     };
     };
   };
   };
 
 
-  type ActionStore = Vuex.ActionInjectee<{ value: number }, RootState>
+  type ActionStore = Vuex.ActionContext<{ value: number }, RootState>
 
 
   const getters = {
   const getters = {
     rootValue: (state: RootState) => state.value
     rootValue: (state: RootState) => state.value

+ 4 - 8
types/test/tsconfig.json

@@ -12,13 +12,9 @@
     "strictNullChecks": true,
     "strictNullChecks": true,
     "noEmit": true
     "noEmit": true
   },
   },
-  "files": [
-    "index.ts",
-    "helpers.ts",
-    "../index.d.ts",
-    "../helpers.d.ts",
-    "../../logger.d.ts",
-    "../vue.d.ts",
-    "../typings/index.d.ts"
+  "include": [
+    "*.ts",
+    "../*.d.ts",
+    "../../dist/logger.d.ts"
   ]
   ]
 }
 }

+ 14 - 0
types/test/vue.ts

@@ -0,0 +1,14 @@
+import Vue = require("vue");
+import * as Vuex from "../index";
+
+const store = new Vuex.Store({
+  state: {
+    value: 1
+  }
+});
+
+const vm = new Vue({
+  store
+});
+
+vm.$store.state.value;

+ 5 - 7
types/tsconfig.json

@@ -8,13 +8,11 @@
       "es2015.promise"
       "es2015.promise"
     ],
     ],
     "noImplicitAny": true,
     "noImplicitAny": true,
-    "strictNullChecks": true
+    "strictNullChecks": true,
+    "noEmit": true
   },
   },
-  "files": [
-    "index.d.ts",
-    "helpers.d.ts",
-    "../logger.d.ts",
-    "vue.d.ts",
-    "typings/index.d.ts"
+  "include": [
+    "*.d.ts",
+    "../dist/logger.d.ts"
   ]
   ]
 }
 }

+ 1 - 4
types/typings.json

@@ -1,7 +1,4 @@
 {
 {
   "name": "vuex",
   "name": "vuex",
-  "main": "index.d.ts",
-  "globalDependencies": {
-    "vue": "registry:dt/vue#1.0.21+20160423143248"
-  }
+  "main": "index.d.ts"
 }
 }

+ 10 - 9
types/vue.d.ts

@@ -2,16 +2,17 @@
  * Extends interfaces in Vue.js
  * Extends interfaces in Vue.js
  */
  */
 
 
-import { Store } from './index'
+import Vue = require("vue");
+import { Store } from "./index";
 
 
-declare global {
-  namespace vuejs {
-    interface ComponentOption {
-      store?: Store<any>;
-    }
+declare module "vue/types/options" {
+  interface ComponentOptions<V extends Vue> {
+    store?: Store<any>;
+  }
+}
 
 
-    interface Vue {
-      $store?: Store<any>;
-    }
+declare module "vue/types/vue" {
+  interface Vue {
+    $store: Store<any>;
   }
   }
 }
 }