From 9d8348ffebd56b7ea423af6884941118d65c9628 Mon Sep 17 00:00:00 2001 From: ktsn Date: Wed, 16 Aug 2017 01:26:46 +0900 Subject: [PATCH 1/3] feat(typings): adapt to the new vue typings BREAKING CHANGE: It is no longer compatible with the old Vue typings --- package.json | 6 +++--- types/index.d.ts | 31 +++++++++++++------------------ types/router.d.ts | 7 +++---- types/test/index.ts | 11 +++++------ types/test/tsconfig.json | 6 +++--- types/typings.json | 4 ---- types/vue.d.ts | 7 +++---- yarn.lock | 32 ++++++++++---------------------- 8 files changed, 40 insertions(+), 64 deletions(-) delete mode 100644 types/typings.json diff --git a/package.json b/package.json index d403ed101..02b5c73cd 100644 --- a/package.json +++ b/package.json @@ -67,11 +67,11 @@ "rollup-plugin-replace": "^1.1.1", "rollup-watch": "^4.0.0", "selenium-server": "^2.53.1", - "typescript": "^2.0.3", + "typescript": "^2.4.2", "uglify-js": "^3.0.17", - "vue": "^2.3.0", + "vue": "DanielRosenwasser/vue#e4a8545", "vue-loader": "^12.0.2", - "vue-template-compiler": "^2.3.0", + "vue-template-compiler": "^2.4.2", "webpack": "^2.4.1", "webpack-dev-middleware": "^1.9.0" } diff --git a/types/index.d.ts b/types/index.d.ts index ba118e243..087275cd7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,21 +1,16 @@ import "./vue"; -import * as R from "./router"; +import { VueRouter } from "./router"; -// `VueRouter` in `export = VueRouter` must be a namespace -// All available types are exported via this namespace -declare namespace VueRouter { - export type RouterMode = R.RouterMode; - export type RawLocation = R.RawLocation; - export type RedirectOption = R.RedirectOption; - export type RouterOptions = R.RouterOptions; - export type RouteConfig = R.RouteConfig; - export type RouteRecord = R.RouteRecord; - export type Location = R.Location; - export type Route = R.Route; - export type NavigationGuard = R.NavigationGuard; -} +export default VueRouter; -// TS cannot merge imported class with namespace, declare a subclass to bypass -declare class VueRouter extends R.VueRouter {} - -export = VueRouter; +export { + RouterMode, + RawLocation, + RedirectOption, + RouterOptions, + RouteConfig, + RouteRecord, + Location, + Route, + NavigationGuard +} from "./router"; diff --git a/types/router.d.ts b/types/router.d.ts index 4d4c6a1d1..cbdd0e99c 100644 --- a/types/router.d.ts +++ b/types/router.d.ts @@ -1,7 +1,6 @@ -import Vue = require("vue"); -import { ComponentOptions, PluginFunction } from "vue"; +import Vue, { ComponentOptions, PluginFunction } from "vue"; -type Component = ComponentOptions | typeof Vue; +type Component = ComponentOptions | typeof Vue; type Dictionary = { [key: string]: T }; export type RouterMode = "hash" | "history" | "abstract"; @@ -13,7 +12,7 @@ export type NavigationGuard = ( next: (to?: RawLocation | false | ((vm: Vue) => any) | void) => void ) => any -declare class VueRouter { +export declare class VueRouter { constructor (options?: RouterOptions); app: Vue; diff --git a/types/test/index.ts b/types/test/index.ts index 5fc8a51fc..b28d20fea 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -1,7 +1,6 @@ -import Vue = require("vue"); -import { ComponentOptions } from "vue"; +import Vue, { ComponentOptions } from "vue"; -import VueRouter = require("../index"); +import VueRouter from "../index"; import { Route, RouteRecord, RedirectOption } from "../index"; Vue.use(VueRouter); @@ -10,7 +9,7 @@ const Home = { template: "
home
" }; const Foo = { template: "
foo
" }; const Bar = { template: "
bar
" }; -const Hook: ComponentOptions = { +const Hook: ComponentOptions = { template: "
hook
", beforeRouteEnter (to, from, next) { @@ -109,7 +108,7 @@ const matched: RouteRecord[] = route.matched; matched.forEach(m => { const path: string = m.path; const components: { - [key: string]: ComponentOptions | typeof Vue + [key: string]: ComponentOptions | typeof Vue } = m.components; const instances: { [key: string]: Vue } = m.instances; const name: string | undefined = m.name; @@ -161,7 +160,7 @@ router.go(-1); router.back(); router.forward(); -const Components: ComponentOptions | typeof Vue = router.getMatchedComponents(); +const Components: (ComponentOptions | typeof Vue)[] = router.getMatchedComponents(); const vm = new Vue({ router, diff --git a/types/test/tsconfig.json b/types/test/tsconfig.json index 064fc138d..0e29224d1 100644 --- a/types/test/tsconfig.json +++ b/types/test/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { "target": "es5", - "module": "commonjs", - "noImplicitAny": true, - "strictNullChecks": true, + "module": "es2015", + "moduleResolution": "node", + "strict": true, "noEmit": true, "lib": [ "es5", diff --git a/types/typings.json b/types/typings.json deleted file mode 100644 index 5b6122aaa..000000000 --- a/types/typings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "vue-router", - "main": "index.d.ts" -} diff --git a/types/vue.d.ts b/types/vue.d.ts index 37c3c44db..bf9a2e805 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -2,9 +2,8 @@ * Augment the typings of Vue.js */ -import Vue = require("vue"); -import VueRouter = require("./index"); -import { Route, RawLocation, NavigationGuard } from "./index"; +import Vue from "vue"; +import VueRouter, { Route, RawLocation, NavigationGuard } from "./index"; declare module "vue/types/vue" { interface Vue { @@ -14,7 +13,7 @@ declare module "vue/types/vue" { } declare module "vue/types/options" { - interface ComponentOptions { + interface ComponentOptions { router?: VueRouter; beforeRouteEnter?: NavigationGuard; beforeRouteLeave?: NavigationGuard; diff --git a/yarn.lock b/yarn.lock index 6b73a12ce..e35c852f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -570,12 +570,6 @@ babel-plugin-transform-strict-mode@^6.24.1: babel-runtime "^6.22.0" babel-types "^6.24.1" -babel-preset-es2015-loose@^8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/babel-preset-es2015-loose/-/babel-preset-es2015-loose-8.0.0.tgz#82ee293ab31329c7a94686b644b62adfbcdc3f57" - dependencies: - modify-babel-preset "^3.1.0" - babel-preset-es2015@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.24.1.tgz#d44050d6bc2c9feea702aaf38d727a0210538939" @@ -3010,12 +3004,6 @@ mocha-nightwatch@3.2.2: mkdirp "0.5.1" supports-color "3.1.2" -modify-babel-preset@^3.1.0: - version "3.2.1" - resolved "https://registry.yarnpkg.com/modify-babel-preset/-/modify-babel-preset-3.2.1.tgz#d7172aa3c0822ed3fc08e308fd0971295136ab50" - dependencies: - require-relative "^0.8.7" - ms@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" @@ -4019,7 +4007,7 @@ require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" -require-relative@0.8.7, require-relative@^0.8.7: +require-relative@0.8.7: version "0.8.7" resolved "https://registry.yarnpkg.com/require-relative/-/require-relative-0.8.7.tgz#7999539fc9e047a37928fa196f8e1563dabd36de" @@ -4563,9 +4551,9 @@ 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.0.3: - version "2.4.0" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.0.tgz#aef5a8d404beba36ad339abf079ddddfffba86dd" +typescript@^2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844" uglify-js@^2.8.27: version "2.8.29" @@ -4700,9 +4688,9 @@ vue-style-loader@^3.0.0: hash-sum "^1.0.2" loader-utils "^1.0.2" -vue-template-compiler@^2.3.0: - version "2.3.4" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.3.4.tgz#5a88ac2c5e4d5d6218e6aa80e7e221fb7e67894c" +vue-template-compiler@^2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.4.2.tgz#5a45d843f148b098f6c1d1e35ac20c4956d30ad1" dependencies: de-indent "^1.0.2" he "^1.1.0" @@ -4711,9 +4699,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.3.0: - version "2.3.4" - resolved "https://registry.yarnpkg.com/vue/-/vue-2.3.4.tgz#5ec3b87a191da8090bbef56b7cfabd4158038171" +vue@DanielRosenwasser/vue#e4a8545: + version "2.4.2" + resolved "https://codeload.github.com/DanielRosenwasser/vue/tar.gz/e4a8545" watchpack@^1.3.1: version "1.3.1" From 800a210597207319e6091e536e732b0424dff2f4 Mon Sep 17 00:00:00 2001 From: ktsn Date: Tue, 12 Sep 2017 23:33:38 +0900 Subject: [PATCH 2/3] chore(package): bump deps --- package-lock.json | 10 ++++------ package.json | 4 ++-- types/router.d.ts | 2 +- types/test/index.ts | 8 ++++---- types/vue.d.ts | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 64ff3a9a2..cf4b84080 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7482,9 +7482,9 @@ "dev": true }, "typescript": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.4.2.tgz", - "integrity": "sha1-+DlfhdRZJ2BnyYiqQYN6j4KHCEQ=", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.5.2.tgz", + "integrity": "sha1-A4qV99m7tCCxvzW6MdTFwd0//jQ=", "dev": true }, "uglify-js": { @@ -7658,9 +7658,7 @@ } }, "vue": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/vue/-/vue-2.4.2.tgz", - "integrity": "sha512-GB5r+CsrCHIB1PoXt4wgBienjF3WGYOIaTK27tDk96sZxpL5RwRrsi9I3ECwFt8x8qAmxT2xk1vsY2Vpcn9nIw==", + "version": "github:HerringtonDarkholme/vue#8901752473c605e3dee1b8312d8dcf1fd72b43ad", "dev": true }, "vue-hot-reload-api": { diff --git a/package.json b/package.json index 02b5c73cd..7d643f069 100644 --- a/package.json +++ b/package.json @@ -67,9 +67,9 @@ "rollup-plugin-replace": "^1.1.1", "rollup-watch": "^4.0.0", "selenium-server": "^2.53.1", - "typescript": "^2.4.2", + "typescript": "^2.5.2", "uglify-js": "^3.0.17", - "vue": "DanielRosenwasser/vue#e4a8545", + "vue": "HerringtonDarkholme/vue#8901752", "vue-loader": "^12.0.2", "vue-template-compiler": "^2.4.2", "webpack": "^2.4.1", diff --git a/types/router.d.ts b/types/router.d.ts index 690bbc719..84ad8a551 100644 --- a/types/router.d.ts +++ b/types/router.d.ts @@ -1,6 +1,6 @@ import Vue, { ComponentOptions, PluginFunction, AsyncComponent } from "vue"; -type Component = ComponentOptions | typeof Vue | AsyncComponent; +type Component = ComponentOptions | typeof Vue | AsyncComponent; type Dictionary = { [key: string]: T }; export type RouterMode = "hash" | "history" | "abstract"; diff --git a/types/test/index.ts b/types/test/index.ts index e53f777ff..f67bb79f3 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -1,4 +1,4 @@ -import Vue, { ComponentOptions } from "vue"; +import Vue, { ComponentOptions, AsyncComponent } from "vue"; import VueRouter from "../index"; import { Route, RouteRecord, RedirectOption } from "../index"; @@ -10,7 +10,7 @@ const Foo = { template: "
foo
" }; const Bar = { template: "
bar
" }; const AsyncComponent = () => Promise.resolve({ template: "
async
" }) -const Hook: ComponentOptions = { +const Hook: ComponentOptions = { template: "
hook
", beforeRouteEnter (to, from, next) { @@ -110,7 +110,7 @@ const matched: RouteRecord[] = route.matched; matched.forEach(m => { const path: string = m.path; const components: { - [key: string]: ComponentOptions | typeof Vue + [key: string]: ComponentOptions | typeof Vue | AsyncComponent } = m.components; const instances: { [key: string]: Vue } = m.instances; const name: string | undefined = m.name; @@ -162,7 +162,7 @@ router.go(-1); router.back(); router.forward(); -const Components: (ComponentOptions | typeof Vue)[] = router.getMatchedComponents(); +const Components: (ComponentOptions | typeof Vue | AsyncComponent)[] = router.getMatchedComponents(); const vm = new Vue({ router, diff --git a/types/vue.d.ts b/types/vue.d.ts index bf9a2e805..0210c9f0e 100644 --- a/types/vue.d.ts +++ b/types/vue.d.ts @@ -13,7 +13,7 @@ declare module "vue/types/vue" { } declare module "vue/types/options" { - interface ComponentOptions { + interface ComponentOptions { router?: VueRouter; beforeRouteEnter?: NavigationGuard; beforeRouteLeave?: NavigationGuard; From b903792b8404c11580787fb6c00c7c1ab686b075 Mon Sep 17 00:00:00 2001 From: ktsn Date: Mon, 9 Oct 2017 22:47:28 +0900 Subject: [PATCH 3/3] chore: bump vue --- package-lock.json | 8 ++++---- package.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index beef2b09e..d2909325c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7664,7 +7664,7 @@ } }, "vue": { - "version": "github:HerringtonDarkholme/vue#8901752473c605e3dee1b8312d8dcf1fd72b43ad", + "version": "github:vuejs/vue#96b97448118de0939bf5f77c9b74cf1613a5a107", "dev": true }, "vue-hot-reload-api": { @@ -7705,9 +7705,9 @@ } }, "vue-template-compiler": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.4.2.tgz", - "integrity": "sha512-sKa2Bdvh+j6V9eQSyJRxsf8fak0FtQkCZ145aYFDVwZBhHOTt1vKrODLo4RelI1dUczKlDCp5aZ9MD7uJOZwvw==", + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.4.4.tgz", + "integrity": "sha512-XdHsNi8Z5WqwuFl/Z5eLKgE2DOEEOdMk1aA459uSgvwyy+pjKLBlQWsUpAtoR6o6Wmpujw6NtinAUGuqSTituQ==", "dev": true, "requires": { "de-indent": "1.0.2", diff --git a/package.json b/package.json index 254efca6f..07ba1756a 100644 --- a/package.json +++ b/package.json @@ -70,9 +70,9 @@ "selenium-server": "^2.53.1", "typescript": "^2.5.2", "uglify-js": "^3.0.17", - "vue": "HerringtonDarkholme/vue#8901752", + "vue": "github:vuejs/vue#96b9744", "vue-loader": "^12.0.2", - "vue-template-compiler": "^2.4.2", + "vue-template-compiler": "^2.4.4", "webpack": "^2.4.1", "webpack-dev-middleware": "^1.9.0" }