Skip to content

Commit 36dd7ce

Browse files
committed
refactor: remove non-null assertions
depends on vuejs/vue#9154
1 parent 3bf014c commit 36dd7ce

File tree

10 files changed

+47
-65
lines changed

10 files changed

+47
-65
lines changed

packages/vuetify/src/components/VBadge/VBadge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default mixins(
5959
staticClass: 'v-badge',
6060
'class': this.classes
6161
}, [
62-
this.$slots.default!,
62+
this.$slots.default,
6363
h('transition', {
6464
props: {
6565
name: this.transition,

packages/vuetify/src/components/VBtn/VBtn.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,19 @@ export default baseMixins.extend<options>().extend({
119119
return this.$createElement(
120120
'div',
121121
{ 'class': 'v-btn__content' },
122-
[this.$slots.default!]
122+
this.$slots.default
123123
)
124124
},
125125
genLoader (): VNode {
126-
const children: VNodeChildren = []
127-
128-
if (!this.$slots.loader) {
129-
children.push(this.$createElement(VProgressCircular, {
130-
props: {
131-
indeterminate: true,
132-
size: 23,
133-
width: 2
134-
}
135-
}))
136-
} else {
137-
children.push(this.$slots.loader)
138-
}
139-
140-
return this.$createElement('span', { 'class': 'v-btn__loading' }, children)
126+
return this.$createElement('span', {
127+
class: 'v-btn__loading'
128+
}, this.$slots.loader || [this.$createElement(VProgressCircular, {
129+
props: {
130+
indeterminate: true,
131+
size: 23,
132+
width: 2
133+
}
134+
})])
141135
},
142136
onRouteChange () {
143137
if (!this.to || !this.$refs.link) return
@@ -155,10 +149,12 @@ export default baseMixins.extend<options>().extend({
155149
render (h): VNode {
156150
const setColor = (!this.outline && !this.flat && !this.disabled) ? this.setBackgroundColor : this.setTextColor
157151
const { tag, data } = this.generateRouteLink(this.classes)
158-
const children = [this.genContent()]
152+
const children = [
153+
this.genContent(),
154+
this.loading && this.genLoader()
155+
]
159156

160-
tag === 'button' && (data.attrs!.type = this.type)
161-
this.loading && children.push(this.genLoader())
157+
if (tag === 'button') data.attrs!.type = this.type
162158

163159
data.attrs!.value = ['string', 'number'].includes(typeof this.value)
164160
? this.value

packages/vuetify/src/components/VChip/VChip.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ export default mixins(Colorable, Themeable, Toggleable).extend({
6363
])
6464
},
6565
genContent (h: CreateElement): VNode {
66-
const children: VNodeChildren = [this.$slots.default!]
67-
68-
this.close && children.push(this.genClose(h))
69-
7066
return h('span', {
7167
staticClass: 'v-chip__content'
72-
}, children)
68+
}, [
69+
this.$slots.default,
70+
this.close && this.genClose(h)
71+
])
7372
}
7473
},
7574

packages/vuetify/src/components/VExpansionPanel/VExpansionPanelContent.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ export default mixins<options &
142142
},
143143

144144
render (h): VNode {
145-
const children = []
146-
147-
this.$slots.header && children.push(this.genHeader())
148-
children.push(h(VExpandTransition, [this.genBody()]))
149-
150145
return h('li', {
151146
staticClass: 'v-expansion-panel__container',
152147
class: this.containerClasses,
@@ -156,6 +151,9 @@ export default mixins<options &
156151
on: {
157152
keydown: this.onKeydown
158153
}
159-
}, children)
154+
}, [
155+
this.$slots.header && this.genHeader(),
156+
h(VExpandTransition, [this.genBody()])
157+
])
160158
}
161159
})

packages/vuetify/src/components/VProgressCircular/VProgressCircular.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export default mixins(Colorable).extend({
131131
},
132132

133133
render (h): VNode {
134-
const info = h('div', { staticClass: 'v-progress-circular__info' }, [this.$slots.default!])
134+
const info = h('div', { staticClass: 'v-progress-circular__info' }, this.$slots.default)
135135
const svg = this.genSvg(h)
136136

137137
return h('div', this.setTextColor(this.color, {

packages/vuetify/src/components/VRating/VRating.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { createRange } from '../../util/helpers'
1616
import mixins from '../../util/mixins'
1717

1818
// Types
19-
import { VNode, VNodeDirective, VNodeChildrenArrayContents } from 'vue'
19+
import { VNode, VNodeDirective, VNodeChildren } from 'vue'
2020

2121
type ItemSlotProps = {
2222
index: number
@@ -188,7 +188,7 @@ export default mixins(
188188
onMouseLeave (): void {
189189
this.runDelay('close', () => (this.hoverIndex = -1))
190190
},
191-
genItem (i: number): VNode | VNodeChildrenArrayContents | string {
191+
genItem (i: number): VNode | VNodeChildren | string {
192192
const props = this.createProps(i)
193193

194194
if (this.$scopedSlots.item) return this.$scopedSlots.item(props)

packages/vuetify/src/components/VSnackbar/VSnackbar.ts

+15-21
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,22 @@ export default mixins(
7171
},
7272

7373
render (h): VNode {
74-
const children: VNodeChildrenArrayContents = []
75-
76-
if (this.isActive) {
77-
children.push(
78-
h('div', {
79-
staticClass: 'v-snack',
80-
class: this.classes,
81-
on: this.$listeners
82-
}, [
83-
h('div', this.setBackgroundColor(this.color, {
84-
staticClass: 'v-snack__wrapper'
85-
}), [
86-
h('div', {
87-
staticClass: 'v-snack__content'
88-
}, this.$slots.default)
89-
])
90-
])
91-
)
92-
}
93-
9474
return h('transition', {
9575
attrs: { name: 'v-snack-transition' }
96-
}, children)
76+
}, this.isActive && [
77+
h('div', {
78+
staticClass: 'v-snack',
79+
class: this.classes,
80+
on: this.$listeners
81+
}, [
82+
h('div', this.setBackgroundColor(this.color, {
83+
staticClass: 'v-snack__wrapper'
84+
}), [
85+
h('div', {
86+
staticClass: 'v-snack__content'
87+
}, this.$slots.default)
88+
])
89+
])
90+
])
9791
}
9892
})

packages/vuetify/src/components/VTimeline/VTimelineItem.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ export default mixins(
5757
}, this.icon)
5858
},
5959
genInnerDot () {
60-
const children = []
61-
62-
this.hasIcon && children.push(this.genIcon())
63-
6460
const data: VNodeData = this.setBackgroundColor(this.color)
6561

6662
return this.$createElement('div', {
6763
staticClass: 'v-timeline-item__inner-dot',
6864
...data
69-
}, children)
65+
}, [this.hasIcon && this.genIcon()])
7066
},
7167
genDot () {
7268
return this.$createElement('div', {
@@ -80,7 +76,7 @@ export default mixins(
8076
genOpposite () {
8177
return this.$createElement('div', {
8278
staticClass: 'v-timeline-item__opposite'
83-
}, [this.$slots.opposite!])
79+
}, this.$slots.opposite)
8480
}
8581
},
8682

packages/vuetify/src/components/VTreeview/VTreeview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export default mixins(
327327
const children: VNodeChildrenArrayContents = this.items.length
328328
? this.items.map(VTreeviewNode.options.methods.genChild.bind(this))
329329
/* istanbul ignore next */
330-
: this.$slots.default!
330+
: this.$slots.default! // TODO: remove type annotation with TS 3.2
331331

332332
return h('div', {
333333
staticClass: 'v-treeview',

packages/vuetify/src/components/VTreeview/VTreeviewNode.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,10 @@ export default mixins<options>(
162162
}, [this.text])
163163
},
164164
genContent () {
165-
// TODO: remove non-null assertions (vuejs/vue#8498)
166165
const children = [
167-
this.$scopedSlots.prepend! && this.$scopedSlots.prepend!(this.scopedProps),
166+
this.$scopedSlots.prepend && this.$scopedSlots.prepend(this.scopedProps),
168167
this.genLabel(),
169-
this.$scopedSlots.append! && this.$scopedSlots.append!(this.scopedProps)
168+
this.$scopedSlots.append && this.$scopedSlots.append(this.scopedProps)
170169
]
171170

172171
return this.$createElement('div', {

0 commit comments

Comments
 (0)