From 96472be6f62a98d3b5d6b784fe341a71ba3a68eb Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 6 Oct 2017 17:41:54 -0400 Subject: [PATCH] types: add types for new features and adjust tests --- .circleci/config.yml | 8 +- flow/options.js | 5 +- package-lock.json | 38 +++ package.json | 2 + .../vue-server-renderer/package-lock.json | 264 +----------------- packages/vue-server-renderer/package.json | 8 +- packages/vue-server-renderer/types/index.d.ts | 6 +- types/options.d.ts | 11 +- types/test/options-test.ts | 29 +- .../types/test.ts => types/test/ssr-test.ts | 23 +- types/test/tsconfig.json | 3 +- 11 files changed, 119 insertions(+), 278 deletions(-) rename packages/vue-server-renderer/types/test.ts => types/test/ssr-test.ts (76%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 265da724..2426aadc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,13 +15,13 @@ jobs: - v1-vue-{{ .Branch }}-{{ checksum "package-lock.json" }} - v1-vue-{{ .Branch }}- - v1-vue- - - run: - name: Install Dependencies - command: npm install + - run: npm install + - run: cd packages/vue-server-renderer && npm install - save_cache: key: v1-vue-{{ .Branch }}-{{ checksum "package-lock.json" }} paths: - node_modules/ + - packages/vue-server-renderer/node_modules - persist_to_workspace: root: ~/project paths: @@ -33,7 +33,7 @@ jobs: - attach_workspace: at: ~/project - run: npm run lint - - run: node_modules/.bin/flow check + - run: npm run flow - run: npm run test:types test-cover: diff --git a/flow/options.js b/flow/options.js index f8891b39..aa87fceb 100644 --- a/flow/options.js +++ b/flow/options.js @@ -12,6 +12,8 @@ declare type InternalComponentOptions = { staticRenderFns?: Array }; +type InjectKey = string | Symbol; + declare type ComponentOptions = { // data data: Object | Function | void; @@ -45,6 +47,7 @@ declare type ComponentOptions = { deactivated?: Function; beforeDestroy?: Function; destroyed?: Function; + errorCaptured?: () => boolean | void; // assets directives?: { [key: string]: Object }; @@ -54,7 +57,7 @@ declare type ComponentOptions = { // context provide?: { [key: string | Symbol]: any } | () => { [key: string | Symbol]: any }; - inject?: { [key: string]: string | Symbol } | Array; + inject?: { [key: string]: InjectKey | { from?: InjectKey, default?: any }} | Array; // component v-model customization model?: { diff --git a/package-lock.json b/package-lock.json index 0757ed8b..e0d856c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,44 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/node": { + "version": "8.0.33", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.33.tgz", + "integrity": "sha512-vmCdO8Bm1ExT+FWfC9sd9r4jwqM7o97gGy2WBshkkXbf/2nLAJQUrZfIhw27yVOtLUev6kSZc4cav/46KbDd8A==", + "dev": true + }, + "@types/source-map": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/@types/source-map/-/source-map-0.5.1.tgz", + "integrity": "sha512-/GVAjL1Y8puvZab63n8tsuBiYwZt1bApMdx58/msQ9ID5T05ov+wm/ZV1DvYC/DKKEygpTJViqQvkh5Rhrl4CA==", + "dev": true + }, + "@types/tapable": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-0.2.4.tgz", + "integrity": "sha512-pclMAvhPnXJcJu1ZZ8bQthuUcdDWzDuxDdbSf6l1U6s4fP6EBiZpPsOZYqFOrbqDV97sXGFSsb6AUpiLfv4xIA==", + "dev": true + }, + "@types/uglify-js": { + "version": "2.6.29", + "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-2.6.29.tgz", + "integrity": "sha512-BdFLCZW0GTl31AbqXSak8ss/MqEZ3DN2MH9rkAyGoTuzK7ifGUlX+u0nfbWeTsa7IPcZhtn8BlpYBXSV+vqGhQ==", + "dev": true, + "requires": { + "@types/source-map": "0.5.1" + } + }, + "@types/webpack": { + "version": "3.0.13", + "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-3.0.13.tgz", + "integrity": "sha512-gWVIAVaGapOPHOrjUQalUqdJWdUIn8w5gpKzz2L14megpB1euvq4HxvGusp9nhtkYGjD/sIg20Zse42b7+7BDw==", + "dev": true, + "requires": { + "@types/node": "8.0.33", + "@types/tapable": "0.2.4", + "@types/uglify-js": "2.6.29" + } + }, "JSONStream": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz", diff --git a/package.json b/package.json index b9a9d005..9cd52f50 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,8 @@ }, "homepage": "https://github.com/vuejs/vue#readme", "devDependencies": { + "@types/node": "^8.0.33", + "@types/webpack": "^3.0.13", "babel-core": "^6.25.0", "babel-eslint": "^7.2.3", "babel-helper-vue-jsx-merge-props": "^2.0.2", diff --git a/packages/vue-server-renderer/package-lock.json b/packages/vue-server-renderer/package-lock.json index b95ea91c..1b25d2ea 100644 --- a/packages/vue-server-renderer/package-lock.json +++ b/packages/vue-server-renderer/package-lock.json @@ -4,44 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "@types/node": { - "version": "7.0.43", - "resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.43.tgz", - "integrity": "sha512-7scYwwfHNppXvH/9JzakbVxk0o0QUILVk1Lv64GRaxwPuGpnF1QBiwdvhDpLcymb8BpomQL3KYoWKq3wUdDMhQ==", - "dev": true - }, - "@types/source-map": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/@types/source-map/-/source-map-0.5.1.tgz", - "integrity": "sha512-/GVAjL1Y8puvZab63n8tsuBiYwZt1bApMdx58/msQ9ID5T05ov+wm/ZV1DvYC/DKKEygpTJViqQvkh5Rhrl4CA==", - "dev": true - }, - "@types/tapable": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/@types/tapable/-/tapable-0.2.4.tgz", - "integrity": "sha512-pclMAvhPnXJcJu1ZZ8bQthuUcdDWzDuxDdbSf6l1U6s4fP6EBiZpPsOZYqFOrbqDV97sXGFSsb6AUpiLfv4xIA==", - "dev": true - }, - "@types/uglify-js": { - "version": "2.6.29", - "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-2.6.29.tgz", - "integrity": "sha512-BdFLCZW0GTl31AbqXSak8ss/MqEZ3DN2MH9rkAyGoTuzK7ifGUlX+u0nfbWeTsa7IPcZhtn8BlpYBXSV+vqGhQ==", - "dev": true, - "requires": { - "@types/source-map": "0.5.1" - } - }, - "@types/webpack": { - "version": "3.0.10", - "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-3.0.10.tgz", - "integrity": "sha512-Xjv1QuWFCVwjxnpcgcdvtR6G4w0tCUpV1Mi5+LPN8w89a/qu8NVbTm1zhD7ZWzvvjE5fMtYNchFHcbjV3u2jyg==", - "dev": true, - "requires": { - "@types/node": "7.0.43", - "@types/tapable": "0.2.4", - "@types/uglify-js": "2.6.29" - } - }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", @@ -150,12 +112,6 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" }, - "typescript": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.5.2.tgz", - "integrity": "sha1-A4qV99m7tCCxvzW6MdTFwd0//jQ=", - "dev": true - }, "vue": { "version": "file:../..", "dev": true, @@ -180,10 +136,6 @@ "negotiator": "0.6.1" } }, - "acorn": { - "version": "3.3.0", - "bundled": true - }, "acorn-dynamic-import": { "version": "2.0.2", "bundled": true, @@ -197,20 +149,6 @@ } } }, - "acorn-jsx": { - "version": "3.0.1", - "bundled": true, - "requires": { - "acorn": "3.3.0" - } - }, - "acorn-object-spread": { - "version": "1.0.0", - "bundled": true, - "requires": { - "acorn": "3.3.0" - } - }, "adm-zip": { "version": "0.4.7", "bundled": true @@ -262,14 +200,6 @@ "version": "1.4.0", "bundled": true }, - "ansi-regex": { - "version": "2.1.1", - "bundled": true - }, - "ansi-styles": { - "version": "2.2.1", - "bundled": true - }, "anymatch": { "version": "1.3.2", "bundled": true, @@ -423,7 +353,6 @@ "version": "6.26.0", "bundled": true, "requires": { - "chalk": "1.1.3", "esutils": "2.0.2", "js-tokens": "3.0.2" } @@ -446,7 +375,6 @@ "debug": "2.6.8", "json5": "0.5.1", "lodash": "4.17.4", - "minimatch": "3.0.4", "path-is-absolute": "1.0.1", "private": "0.1.7", "slash": "1.0.0", @@ -947,10 +875,6 @@ "version": "1.0.2", "bundled": true }, - "balanced-match": { - "version": "1.0.0", - "bundled": true - }, "base64-arraybuffer": { "version": "0.1.5", "bundled": true @@ -1057,14 +981,6 @@ "hoek": "2.16.3" } }, - "brace-expansion": { - "version": "1.1.8", - "bundled": true, - "requires": { - "balanced-match": "1.0.0", - "concat-map": "0.0.1" - } - }, "braces": { "version": "1.8.5", "bundled": true, @@ -1152,25 +1068,6 @@ "pako": "0.2.9" } }, - "buble": { - "version": "0.15.2", - "bundled": true, - "requires": { - "acorn": "3.3.0", - "acorn-jsx": "3.0.1", - "acorn-object-spread": "1.0.0", - "chalk": "1.1.3", - "magic-string": "0.14.0", - "minimist": "1.2.0", - "os-homedir": "1.0.2" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "bundled": true - } - } - }, "buffer": { "version": "4.9.1", "bundled": true, @@ -1202,10 +1099,7 @@ }, "cachedir": { "version": "1.1.1", - "bundled": true, - "requires": { - "os-homedir": "1.0.2" - } + "bundled": true }, "caller-path": { "version": "0.1.0", @@ -1254,17 +1148,6 @@ "deep-eql": "0.1.3" } }, - "chalk": { - "version": "1.1.3", - "bundled": true, - "requires": { - "ansi-styles": "2.2.1", - "escape-string-regexp": "1.0.5", - "has-ansi": "2.0.0", - "strip-ansi": "3.0.1", - "supports-color": "2.0.0" - } - }, "chokidar": { "version": "1.7.0", "bundled": true, @@ -1521,7 +1404,6 @@ "bundled": true, "requires": { "cachedir": "1.1.1", - "chalk": "1.1.3", "cz-conventional-changelog": "1.2.0", "dedent": "0.6.0", "detect-indent": "4.0.0", @@ -1556,7 +1438,6 @@ "fs.realpath": "1.0.0", "inflight": "1.0.6", "inherits": "2.0.3", - "minimatch": "3.0.4", "once": "1.4.0", "path-is-absolute": "1.0.1" } @@ -1621,10 +1502,6 @@ "readable-stream": "2.3.3" } }, - "concat-map": { - "version": "0.0.1", - "bundled": true - }, "concat-stream": { "version": "1.6.0", "bundled": true, @@ -2383,10 +2260,6 @@ "version": "1.0.3", "bundled": true }, - "escape-string-regexp": { - "version": "1.0.5", - "bundled": true - }, "escodegen": { "version": "1.8.1", "bundled": true, @@ -2431,7 +2304,6 @@ "bundled": true, "requires": { "babel-code-frame": "6.26.0", - "chalk": "1.1.3", "concat-stream": "1.6.0", "debug": "2.6.8", "doctrine": "2.0.0", @@ -2472,8 +2344,6 @@ "bundled": true, "requires": { "ansi-escapes": "1.4.0", - "ansi-regex": "2.1.1", - "chalk": "1.1.3", "cli-cursor": "1.0.2", "cli-width": "2.2.0", "figures": "1.7.0", @@ -2482,7 +2352,6 @@ "run-async": "0.1.0", "rx-lite": "3.1.2", "string-width": "1.0.2", - "strip-ansi": "3.0.1", "through": "2.3.8" } }, @@ -2539,8 +2408,7 @@ "version": "3.5.0", "bundled": true, "requires": { - "acorn": "5.1.1", - "acorn-jsx": "3.0.1" + "acorn": "5.1.1" }, "dependencies": { "acorn": { @@ -2572,10 +2440,6 @@ "version": "4.2.0", "bundled": true }, - "estree-walker": { - "version": "0.2.1", - "bundled": true - }, "esutils": { "version": "2.0.2", "bundled": true @@ -2662,10 +2526,7 @@ }, "expand-tilde": { "version": "1.2.2", - "bundled": true, - "requires": { - "os-homedir": "1.0.2" - } + "bundled": true }, "extend": { "version": "3.0.1", @@ -2736,7 +2597,6 @@ "version": "1.7.0", "bundled": true, "requires": { - "escape-string-regexp": "1.0.5", "object-assign": "4.1.1" } }, @@ -2849,10 +2709,7 @@ "dependencies": { "magic-string": { "version": "0.16.0", - "bundled": true, - "requires": { - "vlq": "0.2.2" - } + "bundled": true } } }, @@ -3812,7 +3669,6 @@ "fs.realpath": "1.0.0", "inflight": "1.0.6", "inherits": "2.0.3", - "minimatch": "3.0.4", "once": "1.4.0", "path-is-absolute": "1.0.1" } @@ -3930,13 +3786,6 @@ "har-schema": "1.0.5" } }, - "has-ansi": { - "version": "2.0.0", - "bundled": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, "has-binary": { "version": "0.1.7", "bundled": true, @@ -4016,7 +3865,6 @@ "version": "2.0.0", "bundled": true, "requires": { - "os-homedir": "1.0.2", "os-tmpdir": "1.0.2" } }, @@ -4154,7 +4002,6 @@ "bundled": true, "requires": { "ansi-escapes": "1.4.0", - "chalk": "1.1.3", "cli-cursor": "1.0.2", "cli-width": "2.2.0", "external-editor": "1.1.1", @@ -4165,7 +4012,6 @@ "run-async": "2.3.0", "rx": "4.1.0", "string-width": "1.0.2", - "strip-ansi": "3.0.1", "through": "2.3.8" } }, @@ -4400,7 +4246,6 @@ "requires": { "inflight": "1.0.6", "inherits": "2.0.3", - "minimatch": "3.0.4", "once": "1.4.0", "path-is-absolute": "1.0.1" } @@ -4563,7 +4408,6 @@ "lodash": "3.10.1", "log4js": "0.6.38", "mime": "1.4.0", - "minimatch": "3.0.4", "optimist": "0.6.1", "qjobs": "1.1.5", "range-parser": "1.2.0", @@ -4611,7 +4455,6 @@ "dateformat": "1.0.12", "istanbul": "0.4.5", "lodash": "3.10.1", - "minimatch": "3.0.4", "source-map": "0.5.7" }, "dependencies": { @@ -4654,7 +4497,6 @@ "bundled": true, "requires": { "ansi-styles": "3.2.0", - "escape-string-regexp": "1.0.5", "supports-color": "4.4.0" } }, @@ -5033,7 +4875,6 @@ "bundled": true, "requires": { "ansi-styles": "3.2.0", - "escape-string-regexp": "1.0.5", "supports-color": "4.4.0" } }, @@ -5109,13 +4950,6 @@ "yallist": "2.1.2" } }, - "magic-string": { - "version": "0.14.0", - "bundled": true, - "requires": { - "vlq": "0.2.2" - } - }, "make-dir": { "version": "1.0.0", "bundled": true, @@ -5233,13 +5067,6 @@ "version": "1.0.1", "bundled": true }, - "minimatch": { - "version": "3.0.4", - "bundled": true, - "requires": { - "brace-expansion": "1.1.8" - } - }, "minimist": { "version": "0.0.8", "bundled": true @@ -5263,7 +5090,6 @@ "commander": "2.9.0", "debug": "2.2.0", "diff": "1.4.0", - "escape-string-regexp": "1.0.5", "glob": "7.0.5", "growl": "1.9.2", "json3": "3.3.2", @@ -5293,7 +5119,6 @@ "fs.realpath": "1.0.0", "inflight": "1.0.6", "inherits": "2.0.3", - "minimatch": "3.0.4", "once": "1.4.0", "path-is-absolute": "1.0.1" } @@ -5358,10 +5183,7 @@ "dependencies": { "minimatch": { "version": "3.0.3", - "bundled": true, - "requires": { - "brace-expansion": "1.1.8" - } + "bundled": true }, "q": { "version": "1.4.1", @@ -5520,10 +5342,6 @@ "version": "0.2.1", "bundled": true }, - "os-homedir": { - "version": "1.0.2", - "bundled": true - }, "os-locale": { "version": "1.4.0", "bundled": true, @@ -5963,7 +5781,6 @@ "bundled": true, "requires": { "graceful-fs": "4.1.11", - "minimatch": "3.0.4", "readable-stream": "2.3.3", "set-immediate-shim": "1.0.1" } @@ -6210,14 +6027,6 @@ "rollup-pluginutils": "1.5.2" } }, - "rollup-plugin-buble": { - "version": "0.15.0", - "bundled": true, - "requires": { - "buble": "0.15.2", - "rollup-pluginutils": "1.5.2" - } - }, "rollup-plugin-commonjs": { "version": "8.2.0", "bundled": true, @@ -6239,10 +6048,7 @@ }, "magic-string": { "version": "0.22.4", - "bundled": true, - "requires": { - "vlq": "0.2.2" - } + "bundled": true }, "rollup-pluginutils": { "version": "2.0.1", @@ -6264,8 +6070,7 @@ "version": "1.0.0", "bundled": true, "requires": { - "flow-remove-types-no-whitespace": "1.0.5", - "rollup-pluginutils": "1.5.2" + "flow-remove-types-no-whitespace": "1.0.5" } }, "rollup-plugin-node-resolve": { @@ -6278,32 +6083,6 @@ "resolve": "1.4.0" } }, - "rollup-plugin-replace": { - "version": "1.1.1", - "bundled": true, - "requires": { - "magic-string": "0.15.2", - "minimatch": "3.0.4", - "rollup-pluginutils": "1.5.2" - }, - "dependencies": { - "magic-string": { - "version": "0.15.2", - "bundled": true, - "requires": { - "vlq": "0.2.2" - } - } - } - }, - "rollup-pluginutils": { - "version": "1.5.2", - "bundled": true, - "requires": { - "estree-walker": "0.2.1", - "minimatch": "3.0.4" - } - }, "rollup-watch": { "version": "4.3.1", "bundled": true, @@ -6697,8 +6476,7 @@ "bundled": true, "requires": { "code-point-at": "1.1.0", - "is-fullwidth-code-point": "1.0.0", - "strip-ansi": "3.0.1" + "is-fullwidth-code-point": "1.0.0" } }, "string_decoder": { @@ -6712,13 +6490,6 @@ "version": "0.0.5", "bundled": true }, - "strip-ansi": { - "version": "3.0.1", - "bundled": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, "strip-bom": { "version": "2.0.0", "bundled": true, @@ -6737,17 +6508,12 @@ "version": "2.0.1", "bundled": true }, - "supports-color": { - "version": "2.0.0", - "bundled": true - }, "table": { "version": "3.8.3", "bundled": true, "requires": { "ajv": "4.11.8", "ajv-keywords": "1.5.1", - "chalk": "1.1.3", "lodash": "4.17.4", "slice-ansi": "0.0.4", "string-width": "2.1.1" @@ -7019,10 +6785,7 @@ }, "user-home": { "version": "2.0.0", - "bundled": true, - "requires": { - "os-homedir": "1.0.2" - } + "bundled": true }, "useragent": { "version": "2.2.1", @@ -7090,10 +6853,6 @@ } } }, - "vlq": { - "version": "0.2.2", - "bundled": true - }, "vm-browserify": { "version": "0.0.4", "bundled": true, @@ -7156,7 +6915,6 @@ "version": "2.0.6", "bundled": true, "requires": { - "chalk": "1.1.3", "commander": "2.11.0", "is-my-json-valid": "2.16.1", "pinkie-promise": "2.0.1" @@ -7314,7 +7072,6 @@ "bundled": true, "requires": { "string-width": "1.0.2", - "strip-ansi": "3.0.1", "wrap-ansi": "2.1.0" } } @@ -7386,8 +7143,7 @@ "version": "2.1.0", "bundled": true, "requires": { - "string-width": "1.0.2", - "strip-ansi": "3.0.1" + "string-width": "1.0.2" } }, "wrappy": { diff --git a/packages/vue-server-renderer/package.json b/packages/vue-server-renderer/package.json index bfac83ff..39250cef 100644 --- a/packages/vue-server-renderer/package.json +++ b/packages/vue-server-renderer/package.json @@ -18,9 +18,6 @@ "bugs": { "url": "https://github.com/vuejs/vue/issues" }, - "scripts": { - "test:types": "tsc -p types" - }, "dependencies": { "chalk": "^1.1.3", "hash-sum": "^1.0.2", @@ -32,10 +29,7 @@ "source-map": "0.5.6" }, "devDependencies": { - "@types/node": "^7.0.22", - "@types/webpack": "^3.0.6", - "typescript": "^2.4.2", - "vue": "file:../.." + "vue": "file:../../" }, "homepage": "https://github.com/vuejs/vue/tree/dev/packages/vue-server-renderer#readme" } diff --git a/packages/vue-server-renderer/types/index.d.ts b/packages/vue-server-renderer/types/index.d.ts index d2c8394c..e6c8d62d 100644 --- a/packages/vue-server-renderer/types/index.d.ts +++ b/packages/vue-server-renderer/types/index.d.ts @@ -1,4 +1,4 @@ -import Vue = require('vue'); +import Vue, { VNode, VNodeDirective } from 'vue'; import { Readable } from 'stream'; export declare function createRenderer(options?: RendererOptions): Renderer; @@ -10,6 +10,7 @@ type RenderCallback = (err: Error | null, html: string) => void; interface Renderer { renderToString(vm: Vue, callback: RenderCallback): void; renderToString(vm: Vue, context: object, callback: RenderCallback): void; + renderToString(vm: Vue): Promise; renderToStream(vm: Vue, context?: object): Readable; } @@ -25,9 +26,10 @@ interface RendererOptions { template?: string; inject?: boolean; shouldPreload?: (file: string, type: string) => boolean; + shouldPrefetch?: (file: string, type: string) => boolean; cache?: RenderCache; directives?: { - [key: string]: (vnode: Vue.VNode, dir: Vue.VNodeDirective) => void + [key: string]: (vnode: VNode, dir: VNodeDirective) => void }; } diff --git a/types/options.d.ts b/types/options.d.ts index 7cba394e..c4d822f6 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -80,6 +80,7 @@ export interface ComponentOptions< updated?(): void; activated?(): void; deactivated?(): void; + errorCaptured?(): boolean | void; directives?: { [key: string]: DirectiveFunction | DirectiveOptions }; components?: { [key: string]: Component | AsyncComponent }; @@ -87,7 +88,7 @@ export interface ComponentOptions< filters?: { [key: string]: Function }; provide?: Object | (() => Object); - inject?: { [key: string]: string | symbol } | string[]; + inject?: InjectOptions; model?: { prop?: string; @@ -107,7 +108,7 @@ export interface ComponentOptions< export interface FunctionalComponentOptions> { name?: string; props?: PropDefs; - inject?: { [key: string]: string | symbol } | string[]; + inject?: InjectOptions; functional: boolean; render(this: undefined, createElement: CreateElement, context: RenderContext): VNode; } @@ -169,3 +170,9 @@ export interface DirectiveOptions { componentUpdated?: DirectiveFunction; unbind?: DirectiveFunction; } + +export type InjectKey = string | symbol; + +export type InjectOptions = { + [key: string]: InjectKey | { from?: InjectKey, default?: any } +} | string[]; diff --git a/types/test/options-test.ts b/types/test/options-test.ts index 6a94d95c..e7cd8bac 100644 --- a/types/test/options-test.ts +++ b/types/test/options-test.ts @@ -187,6 +187,9 @@ Vue.component('component', { updated() {}, activated() {}, deactivated() {}, + errorCaptured() { + return true + }, directives: { a: { @@ -224,6 +227,25 @@ Vue.component('component', { delimiters: ["${", "}"] }); +Vue.component('provide-inject', { + provide: { + foo: 1 + }, + inject: { + injectFoo: 'foo', + injectBar: Symbol(), + injectBaz: { from: 'baz' }, + injectQux: { default: 1 }, + injectQuux: { from: 'quuz', default: () => ({ value: 1 })} + } +}) + +Vue.component('provide-function', { + provide: () => ({ + foo: 1 + }) +}) + Vue.component('component-with-scoped-slot', { render (h) { interface ScopedSlotProps { @@ -272,8 +294,11 @@ Vue.component('functional-component', { Vue.component('functional-component-object-inject', { functional: true, inject: { - foo: 'bar', - baz: Symbol() + foo: 'foo', + bar: Symbol(), + baz: { from: 'baz' }, + qux: { default: 1 }, + quux: { from: 'quuz', default: () => ({ value: 1 })} }, render(h) { return h('div') diff --git a/packages/vue-server-renderer/types/test.ts b/types/test/ssr-test.ts similarity index 76% rename from packages/vue-server-renderer/types/test.ts rename to types/test/ssr-test.ts index 381b85cf..a9377a48 100644 --- a/packages/vue-server-renderer/types/test.ts +++ b/types/test/ssr-test.ts @@ -1,9 +1,9 @@ -import Vue = require('vue'); -import VueSSRClientPlugin = require('../client-plugin'); -import VueSSRServerPlugin = require('../server-plugin'); +import Vue, { VNode, VNodeDirective } from '../index'; +import VueSSRClientPlugin = require('../../packages/vue-server-renderer/client-plugin'); +import VueSSRServerPlugin = require('../../packages/vue-server-renderer/server-plugin'); import webpack = require('webpack'); import { readFileSync } from 'fs'; -import { createRenderer, createBundleRenderer } from '../'; +import { createRenderer, createBundleRenderer } from '../../packages/vue-server-renderer'; function createApp (context: any) { return new Vue({ @@ -28,11 +28,24 @@ const context = { ` }; +renderer.renderToString(app, (err, html) => { + if (err) throw err; + const res: string = html; +}); + renderer.renderToString(app, context, (err, html) => { if (err) throw err; const res: string = html; }); +renderer.renderToString(app) + .then(html => { + const res: string = html; + }) + .catch(err => { + throw err; + }); + renderer.renderToStream(app, context).on('data', chunk => { const html = chunk.toString(); }); @@ -71,7 +84,7 @@ const bundleRenderer = createBundleRenderer('/path/to/vue-ssr-server-bundle.json }, directives: { - example (vnode: Vue.VNode, directiveMeta: Vue.VNodeDirective) { + example (vnode: VNode, directiveMeta: VNodeDirective) { // transform vnode based on directive binding metadata } } diff --git a/types/test/tsconfig.json b/types/test/tsconfig.json index be0fef22..784de825 100644 --- a/types/test/tsconfig.json +++ b/types/test/tsconfig.json @@ -18,7 +18,8 @@ "options-test.ts", "plugin-test.ts", "vue-test.ts", - "augmentation-test.ts" + "augmentation-test.ts", + "ssr-test.ts" ], "compileOnSave": false }