From 4b7c170c9c47ddc33a15bbcee0debb64afddd303 Mon Sep 17 00:00:00 2001 From: Blake Newman Date: Tue, 11 Dec 2018 10:21:23 +0000 Subject: [PATCH] [fix] scoped slot typing - Update vue dependencies - Fix scoped slots definitions to be compatible with Vue typings - ScopedSlots can be undefined as there is no guarantee that the scoped slot has to be passed. https://github.com/vuejs/vue/commit/448ba65d2b139b29f1e6891add9925ac22ffe10b - Fixes #11 --- package.json | 6 +++--- test/tsc/basic/componentFactory.tsx | 6 ++++-- test/tsc/basic/test.tsx | 6 ++++-- types/base.d.ts | 6 ++++-- yarn.lock | 16 ++++++++-------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 9c36574..9199b12 100644 --- a/package.json +++ b/package.json @@ -54,13 +54,13 @@ "ts-loader": "^4.4.2", "tsc-test": "^0.1.5", "typescript": "^2.8.1", - "vue": "^2.5.13", + "vue": "^2.5.20", "vue-class-component": "^6.2.0", "vue-router": "^2.5.13", - "vue-template-compiler": "^2.5.13" + "vue-template-compiler": "^2.5.20" }, "peerDependencies": { - "vue": "^2.5.13" + "vue": "^2.5.20" }, "jest": { "moduleFileExtensions": [ diff --git a/test/tsc/basic/componentFactory.tsx b/test/tsc/basic/componentFactory.tsx index 81adef7..fa01462 100644 --- a/test/tsc/basic/componentFactory.tsx +++ b/test/tsc/basic/componentFactory.tsx @@ -136,10 +136,12 @@ function componentFactoryOf() { }, computed: { okNode(): VNode { - return
{this.$scopedSlots.content("foo")}
; + const content = this.$scopedSlots.content + return
{content && content("foo")}
; }, ngNode(): VNode { - return
{this.$scopedSlots.content(0)}
; //// TS2345: '0' is not assignable + const content = this.$scopedSlots.content + return
{content && content(0)}
; //// TS2345: '0' is not assignable } }, render(): VNode { diff --git a/test/tsc/basic/test.tsx b/test/tsc/basic/test.tsx index dc067cb..77307e8 100644 --- a/test/tsc/basic/test.tsx +++ b/test/tsc/basic/test.tsx @@ -170,14 +170,16 @@ function vueClassComponent() { @component class MyComponent2 extends vuetsx.Component { render() { - return
{ this.$scopedSlots.default({ ssprops: "foo" }) }
; + const defaultSlot = this.$scopedSlots.default + return
{ defaultSlot && defaultSlot({ ssprops: "foo" }) }
; } } @component class MyComponent3 extends vuetsx.Component { render() { - return
{ this.$scopedSlots.default({ ssprops: 1 }) }
; //// TS2345: 'number' is not assignable + const defaultSlot = this.$scopedSlots.default + return
{ defaultSlot && defaultSlot({ ssprops: 1 }) }
; //// TS2345: 'number' is not assignable } } diff --git a/types/base.d.ts b/types/base.d.ts index 5271d94..4757a38 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -14,6 +14,8 @@ declare global { export type StringKeyOf = Extract; +type ScopedSlot

= ((props: P) => VNodeChildrenArrayContents | string); + export type KnownAttrs = Pick< VNodeData, "class" | "staticClass" | "key" | "ref" | "slot" | "scopedSlots" @@ -24,9 +26,9 @@ export type KnownAttrs = Pick< domPropsInnerHTML?: string; }; export type ScopedSlots = { - [K in StringKeyOf]: (props: T[K]) => VNodeChildrenArrayContents | string + [K in StringKeyOf]: ScopedSlot | undefined } & { - [name: string]: (props: any) => VNodeChildrenArrayContents | string; + [name: string]: ScopedSlot | undefined; }; export type EventHandlers = { diff --git a/yarn.lock b/yarn.lock index 9aab3b2..6d41246 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4549,18 +4549,18 @@ vue-router@^2.5.13: resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-2.8.1.tgz#9833c9ee57ac83beb0269056fefee71713f20695" integrity sha512-MC4jacHBhTPKtmcfzvaj2N7g6jgJ/Z/eIjZdt+yUaUOM1iKC0OUIlO/xCtz6OZFFTNUJs/1YNro2GN/lE+nOXA== -vue-template-compiler@^2.5.13: - version "2.5.13" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.13.tgz#12a2aa0ecd6158ac5e5f14d294b0993f399c3d38" - integrity sha512-15HWSgIxrGUcV0v7QRen2Y3fQsbgxXwMvjT/5XKMO0ANmaCcNh7y2OeIDTAuSGeosjb9+E1Pn2PHZ61VQWEgBQ== +vue-template-compiler@^2.5.20: + version "2.5.20" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.20.tgz#b9c01741b7e0261d1c5aac5937c93bde98f880f0" + integrity sha512-aGJRLd1bJZi6oerGwCQVaDqvQ1T3dhCbNg9C2gNwzoKnyA3BmYfAWy8OQ3OhOebTri8o4YcLeXfwOOxtOKFfmA== dependencies: de-indent "^1.0.2" he "^1.1.0" -vue@^2.5.13: - version "2.5.13" - resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.13.tgz#95bd31e20efcf7a7f39239c9aa6787ce8cf578e1" - integrity sha512-3D+lY7HTkKbtswDM4BBHgqyq+qo8IAEE8lz8va1dz3LLmttjgo0FxairO4r1iN2OBqk8o1FyL4hvzzTFEdQSEw== +vue@^2.5.20: + version "2.5.20" + resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.20.tgz#79fff9ccaa10cc37e7a7239b4c7adfac94df81ba" + integrity sha512-kVLZi8RWOk8qwAt+a0bVDy9VV5Zzcnj0fLCMyKLx1dmEBjqmYJYRWHvPwiypiJBtJkdmROy5NP5hyDqTdfBcvQ== w3c-hr-time@^1.0.1: version "1.0.1"