Skip to content

Type 'X' is missing the following properties from type 'Y' #1857

@cmitjans-at-wiris

Description

@cmitjans-at-wiris

When a reference to a Typescript Class is created, and the class has private properties/methods, this TS error appears (although the code compiles):

Type 'X' is missing the following properties from type 'Y': (private properties/methods)

Minimal reproducible example:

Class:

export default class MyClass {
  private value: number = 0

  public setNumber(newValue: number) {
    this.value = newValue
  }

  public getNumber(): number {
    return this.value
  }

  private privateMethod() {

  }
}

Parent component:

<template>
  <Child :my-class="myClass" /> <!--Type '{ setNumber: (newValue: number) => void; getNumber: () => number; }' is missing the following properties from type 'MyClass': value, privateMethodts -->
</template>

<script setup lang="ts">
import MyClass from './my_class';

const myClass = ref(new MyClass());
</script>

Child component:

<template>
  <h1> {{ myClass.getNumber() }} </h1>
</template>

<script setup lang="ts">
import MyClass from '~~/domain/my_class'

defineProps<{
  myClass: MyClass
}>();

</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions