Subscribe on changes!

Overloads for render function cause needless check

avatar
Feb 15th 2022

Version

3.2.31

Reproduction link

www.typescriptlang.org/play

import { h, Component } from 'vue'

const serializers = {
    Paragraph: 'p',
    Component: {} as Component<any>
}

const sampleComponent = serializers['' as keyof typeof serializers]

// This is a type error
h(sampleComponent)
h(sampleComponent, '')

// This isn't
if (typeof sampleComponent === 'string') {
    h(sampleComponent)
    h(sampleComponent, '')
} else {
    h(sampleComponent)
    h(sampleComponent, '')
}

Steps to reproduce

If we have a component to render that is string | Component we have to narrow its type even if we are calling h() in a way that doesn't make a difference.

What is expected?

I expect not to have to narrow the type in this instance.

What is actually happening?

I am having to add a needless check.