[Vuejs]-What causes the property does not exist on type ObjectConstructor error in this Vue 3 app?

1👍

Don’t use classes for typing.

Classes are templates for creating object instances. To declare their types you should use interfaces and/or types.

In short, change this:

export class Movie {
    id?: number;
    adult?: boolean;
    backdrop_path?: string;
    poster_path?: string;
    title?: string;
    tagline?: string;
    overview?: string;
    genre_ids?: any;
    original_title?: string;
    release_date?: string;
    runtime?: number;
    vote_average?: string;
}

…to this:

export interface Movie {
    id?: number;
    adult?: boolean;
    backdrop_path?: string;
    poster_path?: string;
    title?: string;
    tagline?: string;
    overview?: string;
    genre_ids?: any;
    original_title?: string;
    release_date?: string;
    runtime?: number;
    vote_average?: string;
}

And you’re good to go.

👤tao

Leave a comment