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

Better type definition required #14

Open
MartianH opened this issue Nov 10, 2022 · 0 comments
Open

Better type definition required #14

MartianH opened this issue Nov 10, 2022 · 0 comments

Comments

@MartianH
Copy link

MartianH commented Nov 10, 2022

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.
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

1 participant