fix(runtime-core): fix slot fallback + slots typing

fix #773
This commit is contained in:
Evan You 2020-02-24 23:05:35 -05:00
parent 19a799c28b
commit 4a5b91bd1f
3 changed files with 7 additions and 7 deletions

View File

@ -12,7 +12,7 @@ import { isKeepAlive } from './components/KeepAlive'
export type Slot = (...args: any[]) => VNode[] export type Slot = (...args: any[]) => VNode[]
export type InternalSlots = { export type InternalSlots = {
[name: string]: Slot [name: string]: Slot | undefined
} }
export type Slots = Readonly<InternalSlots> export type Slots = Readonly<InternalSlots>

View File

@ -1,5 +1,5 @@
import { Data } from '../component' import { Data } from '../component'
import { Slot } from '../componentSlots' import { Slots } from '../componentSlots'
import { import {
VNodeArrayChildren, VNodeArrayChildren,
openBlock, openBlock,
@ -11,7 +11,7 @@ import { PatchFlags } from '@vue/shared'
import { warn } from '../warning' import { warn } from '../warning'
export function renderSlot( export function renderSlot(
slots: Record<string, Slot>, slots: Slots,
name: string, name: string,
props: Data = {}, props: Data = {},
// this is not a user-facing function, so the fallback is always generated by // this is not a user-facing function, so the fallback is always generated by
@ -20,7 +20,7 @@ export function renderSlot(
): VNode { ): VNode {
let slot = slots[name] let slot = slots[name]
if (__DEV__ && slot.length > 1) { if (__DEV__ && slot && slot.length > 1) {
warn( warn(
`SSR-optimized slot function detected in a non-SSR-optimized render ` + `SSR-optimized slot function detected in a non-SSR-optimized render ` +
`function. You need to mark this component with $dynamic-slots in the ` + `function. You need to mark this component with $dynamic-slots in the ` +

View File

@ -103,14 +103,14 @@ describe('class', () => {
const component1 = defineComponent({ const component1 = defineComponent({
props: {}, props: {},
render() { render() {
return this.$slots.default()[0] return this.$slots.default!()[0]
} }
}) })
const component2 = defineComponent({ const component2 = defineComponent({
props: {}, props: {},
render() { render() {
return this.$slots.default()[0] return this.$slots.default!()[0]
} }
}) })
@ -122,7 +122,7 @@ describe('class', () => {
{ {
class: 'staticClass' class: 'staticClass'
}, },
[this.$slots.default()] [this.$slots.default!()]
) )
} }
}) })