Skip to content

Commit

Permalink
Be explicit about return types to avoid tsc complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed May 14, 2020
1 parent eabda5f commit 3587049
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/remotedb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class QueryInterface {
/**
* Make a query to the remote database connection.
*/
async query<T extends Query>(opts: QueryOpts<T>) {
async query<T extends Query>(opts: QueryOpts<T>): Promise<HandlerReturn<T>> {
const {query, queryDescriptor, args} = opts;
const conn = this.#conn;

Expand Down
12 changes: 6 additions & 6 deletions src/remotedb/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type Options<T extends MessageType> = {
args: Field[];
};

type ResponseType<T> = T extends Response ? T : never;
type Data<T> = ReturnType<typeof responseTransform[ResponseType<T>]>;

/**
* Representation of a set of fields sequenced into a known message format.
*/
Expand Down Expand Up @@ -165,16 +168,13 @@ export class Message<T extends MessageType = MessageType> {
*
* Currently only supports representing response messages.
*/
get data() {
type ResponseType = T extends Response ? T : never;
type Data = ReturnType<typeof responseTransform[ResponseType]>;

const type = this.type as ResponseType;
get data(): Data<T> {
const type = this.type as ResponseType<T>;

if (!Object.values(Response).includes(type)) {
throw new Error('Representation of non-responses is not currently supported');
}

return responseTransform[type](this.args) as Data;
return responseTransform[type](this.args) as Data<T>;
}
}

0 comments on commit 3587049

Please sign in to comment.