Skip to content

Typescript: Type 'null' is not assignable to type 'PropValidator<any>' #8120

@KaelWD

Description

@KaelWD

Version

2.5.16

Reproduction link

Vue.component('union-prop', {
  props: {
    anything: null,
    primitive: [String, Number],
    object: [Cat, User],
    regex: RegExp,
    mixed: [RegExp, Array],
    union: [User, Number] as {new(): User | Number}[] // requires annotation
  },
  data() {
    this.anything;
    this.primitive;
    this.object;
    this.union;
    this.regex.compile;
    this.mixed;
    return {
      fixedSize: this.union,
    }
  }
});

Steps to reproduce

Paste it into options-test.ts and run yarn test:types

What is expected?

No errors, type should be any

What is actually happening?

Type 'null' is not assignable to type 'PropValidator'

It works with strictNullChecks disabled, but the type is {} instead of any

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions