Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue-api-query @types #104

Closed
alvaro-canepa opened this issue Apr 25, 2020 · 1 comment
Closed

vue-api-query @types #104

alvaro-canepa opened this issue Apr 25, 2020 · 1 comment

Comments

@alvaro-canepa
Copy link

Below is the .d.ts types that I use.
I'm a newbie with TS, so, maybe is a better way to write it.

declare module "vue-api-query" {
  import { AxiosInstance, AxiosRequestConfig, AxiosPromise } from "axios";

  type ThisClass<InstanceType extends Model> = {
    new (...args: any[]): InstanceType;
  };
  type Constructor<T> = new (...args: any[]) => T;

  interface Class<T> {
    super(...args: any[]): T;
  }

  export class Model {
    constructor(...args: any[]);
    super: Constructor<this>;

    static $http: AxiosInstance;
    $http: AxiosInstance;
    mutations?: object;

    /**
     * Settings
     */
    endpoint(): string;
    resource(): string;
    primaryKey(): string;
    getPrimaryKey(): string;
    baseURL(): string;
    request(config: AxiosRequestConfig): AxiosPromise<any>;
    _from(url: string): void;

    /**
     * Query
     */
    append<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    custom<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    include<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    select<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    orderBy<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    where<T extends Model>(this: ThisClass<T>, field: string, value: any): T;
    whereIn<T extends Model>(
      this: ThisClass<T>,
      field: string,
      array: any[]
    ): T;
    limit<T extends Model>(this: ThisClass<T>, value: number): T;
    page<T extends Model>(this: ThisClass<T>, value: number): T;
    params<T extends Model>(this: ThisClass<T>, payload: object): T;
    for<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    hasMany<T>(model: T): T;

    /**
     * Results
     */
    $find(identifier: number | string): any;
    $first(): any;
    $get(): any;
    find<T extends Model>(
      this: ThisClass<T>,
      identifier: number | string
    ): Promise<T>;
    first<T extends Model>(this: ThisClass<T>): Promise<T>;
    get<T extends Model>(this: ThisClass<T>): Promise<T[]>;
    delete(): Promise<any>;
    save<T extends Model>(this: ThisClass<T>): Promise<T>;
    attach(params: object): Promise<any>;
    sync(params: object): Promise<any>;

    /**
     * Helpers
     */
    hasId(): boolean;
    isValidId(id: any): boolean;

    parameterNames(): any;

    static $find(id: number | string): any;
    static $first(): any;
    static $get(): any;
    static append<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    static custom<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    static find(id: number | string): Model;
    static first<T extends Model>(this: ThisClass<T>): T;
    static get(): any;
    static include(...args: any[]): Model;
    static instance<T extends Model>(this: ThisClass<T>): T;
    static limit(value: any): Model;
    static orderBy(...args: any[]): Model;
    static page(value: any): Model;
    static params<T extends Model>(this: ThisClass<T>, payload: object): T;
    static select<T extends Model>(this: ThisClass<T>, ...args: any[]): T;
    static where<T extends Model>(
      this: ThisClass<T>,
      field: string,
      value: any
    ): T;
    static whereIn<T extends Model>(
      this: ThisClass<T>,
      field: string,
      array: any[]
    ): T;
  }
}
@robsontenorio
Copy link
Owner

Thanks again @alvaro-canepa !

For now, i am not intend to provide official typescript support. I am closing it for now, but will keep it for future reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants