Skip to content

Commit

Permalink
[fix] scoped slot typing
Browse files Browse the repository at this point in the history
- 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. vuejs/vue@448ba65
- Fixes #11
  • Loading branch information
blake-newman committed Dec 11, 2018
1 parent 8b7aa33 commit 4b7c170
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 4 additions & 2 deletions test/tsc/basic/componentFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ function componentFactoryOf() {
},
computed: {
okNode(): VNode {
return <div>{this.$scopedSlots.content("foo")}</div>;
const content = this.$scopedSlots.content
return <div>{content && content("foo")}</div>;
},
ngNode(): VNode {
return <div>{this.$scopedSlots.content(0)}</div>; //// TS2345: '0' is not assignable
const content = this.$scopedSlots.content
return <div>{content && content(0)}</div>; //// TS2345: '0' is not assignable
}
},
render(): VNode {
Expand Down
6 changes: 4 additions & 2 deletions test/tsc/basic/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ function vueClassComponent() {
@component
class MyComponent2 extends vuetsx.Component<Props, Events, ScopedSlots> {
render() {
return <div>{ this.$scopedSlots.default({ ssprops: "foo" }) }</div>;
const defaultSlot = this.$scopedSlots.default
return <div>{ defaultSlot && defaultSlot({ ssprops: "foo" }) }</div>;
}
}

@component
class MyComponent3 extends vuetsx.Component<Props, Events, ScopedSlots> {
render() {
return <div>{ this.$scopedSlots.default({ ssprops: 1 }) }</div>; //// TS2345: 'number' is not assignable
const defaultSlot = this.$scopedSlots.default
return <div>{ defaultSlot && defaultSlot({ ssprops: 1 }) }</div>; //// TS2345: 'number' is not assignable
}
}

Expand Down
6 changes: 4 additions & 2 deletions types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare global {

export type StringKeyOf<T> = Extract<keyof T, string>;

type ScopedSlot<P = any> = ((props: P) => VNodeChildrenArrayContents | string);

export type KnownAttrs = Pick<
VNodeData,
"class" | "staticClass" | "key" | "ref" | "slot" | "scopedSlots"
Expand All @@ -24,9 +26,9 @@ export type KnownAttrs = Pick<
domPropsInnerHTML?: string;
};
export type ScopedSlots<T> = {
[K in StringKeyOf<T>]: (props: T[K]) => VNodeChildrenArrayContents | string
[K in StringKeyOf<T>]: ScopedSlot<T[K]> | undefined
} & {
[name: string]: (props: any) => VNodeChildrenArrayContents | string;
[name: string]: ScopedSlot | undefined;
};

export type EventHandlers<E> = {
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4b7c170

Please sign in to comment.