Digital-Alchemy-TS / hass

Typescript APIs for Home Assistant. Includes rest & websocket bindings
https://docs.digital-alchemy.app
MIT License
8 stars 2 forks source link

Create interface that can centrally provide responses for hass.call reponse required calls #66

Open zoe-codez opened 2 months ago

zoe-codez commented 2 months ago

🪤 Context

Right now it's only possible to associate types with a service call response manually (per-call), or have it hard coded in type-writer.

It'd be nice if there were an interface that could store these responses, and be friendly towards declaration merging to append to.

declare module "@digital-alchemy/hass" {
  export interface CallServiceResponses {
    "domain.get_data": { ... }
  }
}
hass.call.domain.get_data = function<T = GetResponse<"domain.get_data">>(params): Promise<T> { ... }

This can be coded into type-writer as a pattern. If a response exists in the interface, then use that as a return. Otherwise unknown.

🩻 Additional details

This should be friendly towards the creation of external helper libraries that want to supplement types. Don't want to collect types from every integration as part of this repo. This could let another repo merge the types, and publish that as a package. Someone wanting to use them can do

main.ts

import "@cool-person/helper-types";

// helpers available anywhere in project now

Might require some tweaks to the proposed types workflow above, want a minimum number of helper types

zoe-codez commented 2 months ago

Follow up to #34