Suggest forking definitelytyped and creating @types/framework-x per instructions here:
https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package
We can publish our own type definitions, but this forces the IDEs of users of the library to resolve our definitions to the type definitions. This way there's at least the option to install types optionally and if they're not installed goto will resolve directly to source code.
I'll push a branch with the type defs but in case not here's what we have:
declare type Db = object
declare function getState(): Db
// declare interface FrameworkX {
// getState(): Db
// }
declare module "framework-x" {
export type EventName = string
export type EventData = any
export type Event = [EventName, EventData?]
export type DbFn = (db: Db) => Db
export type FxName = "db" | "dispatch" | string
export type FxArg = any
export type Effects = { db: DbFn | Db } & { [k in FxName]: FxArg }
| [FxName, FxArg][]
export function dispatch(...event: Event): void;
export function dispatch(eventType: EventName, ...args: [any]): void;
export type Coeffects = { db: Db } & { [k: string]: any }
export type Handler = (cofx: Coeffects, eventType: EventName, args: EventData) => Effects | void
export function regEventFx(eventType: EventName, handler: Handler): void;
export interface Effect {
(x: any): any
}
export function regFx(name: FxName, fn: Effect): void
export function getState(): Db
type StateListener = (db: Db) => void
export function subscribeToState(fn: StateListener): void
type EventListener = (type: string, payload: any, effects: any) => any
export interface Store {
getState(): Db
dispatch(...event: Event): void;
dispatch(eventType: EventName, ...args: [any]): void;
regEventFx(eventType: EventName, handler: Handler): void;
regFx(name: FxName, fn: Effect): void
subscribeToState(fn: StateListener): void
}
export function createStore(initialState?: object): Store
}
Suggest forking definitelytyped and creating @types/framework-x per instructions here:
https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package
We can publish our own type definitions, but this forces the IDEs of users of the library to resolve our definitions to the type definitions. This way there's at least the option to install types optionally and if they're not installed goto will resolve directly to source code.
I'll push a branch with the type defs but in case not here's what we have: