Search code examples
typescriptvue.jswebstormvuejs3typescript-class

how to define ref data as class type in vue3 with ts


I want to use ref to create a class . It can be used as a class instance which can be called by .

in my ts file

export default declare class Cropper {
  ....
}

in my vue3 file

const cropper =ref<Cropper||undefined||null>()

but it dosen't work enter image description here


Solution

  • The syntax for | union types in TypeScript isn't the same as || (logical OR) in JavaScript.

    It should be:

    const cropper = ref<Cropper|undefined|null>()