Skip to content

Typescript definition file #107

@Juancoll

Description

@Juancoll

Hey there!

Lately we worked a lot with Typescript and React and we have noticed that nobody has yet made a declaration file for typescript on FreezerJS. We have tried to create a d.ts file ourselves for our project, but we have noticed that all fields of the state can access the functions of the listener, so we can't declare the state as 'any' type.

Here's our code for d.ts file:

declare interface IFreezerOptions{
    mutable:boolean;
    live:boolean;
    freezeInstances:boolean;
}

declare interface IFreezerListener {
    on:(eventName: string, cb: (...params:any[]) => void) => void;

    once:(eventName: string, cb: (...params:any[]) => void) => void;
    
    off:(eventName: string, cb: (...params:any[]) => void) => void;

    emit:(eventName:string, ...params:any[]) => void;
}

declare class Freezer implements IFreezerListener{
    new (a: any, b:IFreezerOptions) : Freezer;

    set(state:any):void;
    set(key:any, state:any):void;

    reset(newData:any):void;

    get():any;
    getEventHub(): IFreezerListener;

    on(eventName: string, cb: (...params:any[]) => void) : void;

    once(eventName: string, cb: (...params:any[]) => void) : void;
    off(eventName: string, cb: (...params:any[]) => void) : void;
    emit(eventName:string, ...params:any[]) : void;
}

declare namespace Freezer{
}

export = Freezer;

Is there any way to type the library by ourselvers or are we just squealing because it's impossible?

Thanks a lot to everybody!

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