Skip to content

PropType doesn't take undefined for optional props into account #11454

Open
@jacekkarczmarczyk

Description

@jacekkarczmarczyk

Version

2.6.11

Steps to reproduce

Create component with optional prop being an object and try to access its property

import Vue, { PropType } from 'vue';

Vue.extend({
  props: {
    container: Object as PropType<{ n: number }>,
    // or container: Number
  },

  mounted () {
    // should fail because this.container could be undefined
    console.log(this.container.n);
  },
});

What is expected?

TS error: Object is possibly undefined

What is actually happening?

No error

Note

It works as expected with Composition API plugin

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions