Skip to content

Better type definition required #14

Description

@MartianH

Greetings,

The type definition in this client is rudimental. Types in question:

import Config from './config';
import DefaultConfig from './default-config';
import VaultResponse from './vault-response';
export declare type VaultFunctionWithoutData = (path: string) => Promise<any>;
export declare type VaultFunctionWithData = (path: string, data: any) => Promise<any>;
export interface VaultFunc {
    (config: Config): Promise<VaultResponse>;
    create?: (defaultConfig: DefaultConfig) => VaultFunc;
    read: VaultFunctionWithoutData;
    list: VaultFunctionWithoutData;
    delete: VaultFunctionWithoutData;
    help: VaultFunctionWithoutData;
    write: VaultFunctionWithData;
}
export default VaultFunc;
  1. VaultFunc returns itself on create that one is just odd. While axios does something similar [Link] it returns an instance interface it extend from. Which brings me to. This also means that after returning an instance. You can STILL call create according to type definition...
  2. All vault function return the same interface. None of them are generic all of them return an any promise. This will not play nice with strict checks and no implicit any configs.
  3. create? is optional which makes it potentially undefined. As such I have to do vault.create?({ /* [...] */ }) to avoid an error/warning. This feels awkward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions