Skip to content

Commit ff229e6

Browse files
committed
types: add typing support
1 parent b9b43f8 commit ff229e6

10 files changed

+43
-34
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"build:main": "node build/build.main.js",
2121
"build:logger": "rollup -c build/rollup.logger.config.js",
2222
"lint": "eslint src test",
23-
"test": "npm run lint && npm run test:unit && npm run test:ssr && npm run test:e2e",
23+
"test": "npm run lint && npm run test:unit && npm run test:ssr && npm run test:types && npm run test:e2e",
2424
"test:unit": "rollup -c build/rollup.dev.config.js && jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
2525
"test:e2e": "node test/e2e/runner.js",
2626
"test:ssr": "rollup -c build/rollup.dev.config.js && cross-env VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
@@ -43,6 +43,7 @@
4343
"vue": "3.0.0-beta.2"
4444
},
4545
"devDependencies": {
46+
"@types/node": "^13.13.0",
4647
"@vue/compiler-sfc": "3.0.0-beta.2",
4748
"babel-core": "^6.22.1",
4849
"babel-loader": "^7.1.2",
@@ -66,7 +67,7 @@
6667
"rollup-plugin-replace": "^2.1.0",
6768
"terser": "^3.17.0",
6869
"todomvc-app-css": "^2.1.0",
69-
"typescript": "^3.7.2",
70+
"typescript": "^3.8.3",
7071
"vue": "3.0.0-beta.2",
7172
"vue-loader": "16.0.0-alpha.3",
7273
"vue-template-compiler": "^2.5.22",

types/helpers.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import Vue from 'vue';
1+
import { ComponentPublicInstance } from 'vue';
22
import { Dispatch, Commit } from './index';
33

44
type Computed = () => any;
55
type InlineComputed<T extends Function> = T extends (...args: any[]) => infer R ? () => R : never
66
type MutationMethod = (...args: any[]) => void;
77
type ActionMethod = (...args: any[]) => Promise<any>;
88
type InlineMethod<T extends (fn: any, ...args: any[]) => any> = T extends (fn: any, ...args: infer Args) => infer R ? (...args: Args) => R : never
9-
type CustomVue = Vue & Record<string, any>;
9+
type CustomVue = ComponentPublicInstance & Record<string, any>;
1010

1111
interface Mapper<R> {
1212
<Key extends string>(map: Key[]): { [K in Key]: R };

types/index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _Vue, { WatchOptions } from "vue";
1+
import { App, WatchOptions, InjectionKey } from "vue";
22

33
// augment typings of Vue.js
44
import "./vue";
@@ -13,6 +13,8 @@ export declare class Store<S> {
1313
readonly state: S;
1414
readonly getters: any;
1515

16+
install(app: App, injectKey?: InjectionKey<Store<any>>): void;
17+
1618
replaceState(state: S): void;
1719

1820
dispatch: Dispatch;
@@ -36,7 +38,7 @@ export declare class Store<S> {
3638
}): void;
3739
}
3840

39-
export declare function install(Vue: typeof _Vue): void;
41+
export function createStore<S>(options: StoreOptions<S>): Store<S>;
4042

4143
export interface Dispatch {
4244
(type: string, payload?: any, options?: DispatchOptions): Promise<any>;
@@ -139,7 +141,6 @@ export interface ModuleTree<R> {
139141

140142
declare const _default: {
141143
Store: typeof Store;
142-
install: typeof install;
143144
mapState: typeof mapState,
144145
mapMutations: typeof mapMutations,
145146
mapGetters: typeof mapGetters,

types/test/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Vue from "vue";
1+
import { createApp } from "vue";
22

33
import {
44
mapState,
@@ -10,7 +10,7 @@ import {
1010

1111
const helpers = createNamespacedHelpers('foo');
1212

13-
new Vue({
13+
createApp({
1414
computed: {
1515
...mapState(["a"]),
1616
...mapState('foo', ["b"]),

types/test/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import Vue from "vue";
21
import * as Vuex from "../index";
32
import createLogger from "../../dist/logger";
43

5-
Vue.use(Vuex);
6-
74
namespace StoreInstance {
85
const store = new Vuex.Store({
96
state: {

types/test/tsconfig.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
4-
"module": "es2015",
3+
"target": "esnext",
4+
"module": "esnext",
55
"moduleResolution": "node",
66
"lib": [
7-
"es5",
8-
"dom",
9-
"es2015.promise",
10-
"es2015.core"
7+
"esnext",
8+
"dom"
9+
],
10+
"types": [
11+
"node"
1112
],
1213
"strict": true,
1314
"noEmit": true

types/test/vue.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Vue from "vue";
1+
import { createApp } from "vue";
22
import * as Vuex from "../index";
33

44
const store = new Vuex.Store({
@@ -7,8 +7,10 @@ const store = new Vuex.Store({
77
}
88
});
99

10-
const vm = new Vue({
10+
const app = createApp({
1111
store
1212
});
1313

14+
const vm = app.mount('#el')
15+
1416
vm.$store.state.value;

types/tsconfig.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
4-
"module": "es2015",
3+
"target": "esnext",
4+
"module": "esnext",
55
"moduleResolution": "node",
66
"lib": [
7-
"es5",
8-
"dom",
9-
"es2015.promise"
7+
"esnext",
8+
"dom"
9+
],
10+
"types": [
11+
"node"
1012
],
1113
"strict": true,
1214
"noEmit": true

types/vue.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
* Extends interfaces in Vue.js
33
*/
44

5-
import Vue, { ComponentOptions } from "vue";
5+
import { ComponentCustomOptions, ComponentCustomProperties } from "vue";
66
import { Store } from "./index";
77

8-
declare module "vue/types/options" {
9-
interface ComponentOptions<V extends Vue> {
8+
declare module "@vue/runtime-core" {
9+
interface ComponentCustomOptions {
1010
store?: Store<any>;
1111
}
1212
}
1313

14-
declare module "vue/types/vue" {
15-
interface Vue {
14+
declare module "@vue/runtime-core" {
15+
interface ComponentCustomProperties {
1616
$store: Store<any>;
1717
}
1818
}

yarn.lock

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,11 @@
929929
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
930930
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==
931931

932+
"@types/node@^13.13.0":
933+
version "13.13.0"
934+
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.0.tgz#30d2d09f623fe32cde9cb582c7a6eda2788ce4a8"
935+
integrity sha512-WE4IOAC6r/yBZss1oQGM5zs2D7RuKR6Q+w+X2SouPofnWn+LbCqClRyhO3ZE7Ix8nmFgo/oVuuE01cJT2XB13A==
936+
932937
933938
version "3.0.0-beta.11"
934939
resolved "https://registry.yarnpkg.com/@vue/babel-preset-app/-/babel-preset-app-3.0.0-beta.11.tgz#c8b889aa73464050f9cd3f9dc621951d85c24508"
@@ -9746,10 +9751,10 @@ typedarray@^0.0.6:
97469751
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
97479752
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
97489753

9749-
typescript@^3.7.2:
9750-
version "3.7.2"
9751-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb"
9752-
integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==
9754+
typescript@^3.8.3:
9755+
version "3.8.3"
9756+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
9757+
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
97539758

97549759
uc.micro@^1.0.1, uc.micro@^1.0.5:
97559760
version "1.0.5"

0 commit comments

Comments
 (0)