Skip to content

Commit

Permalink
fix: Omit then from Reply to correctly infer AsReply return 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
Coobaha committed Feb 24, 2021
1 parent b770776 commit a2a143c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
16 changes: 5 additions & 11 deletions src/typed-fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ const addSchema = <

export default addSchema;

export type Missing<Candidate extends any, MaybeRequired extends any> = [Candidate, MaybeRequired] extends [
never,
never,
]
type Missing<Candidate extends any, MaybeRequired extends any> = [Candidate, MaybeRequired] extends [never, never]
? false
: [Candidate] extends [never]
? true
Expand Down Expand Up @@ -146,6 +143,7 @@ interface Reply<
| 'request'
| 'getHeader'
| 'getHeaders'
| 'then'
> {
asReply(this: any): AsReply;
matches<
Expand Down Expand Up @@ -227,6 +225,7 @@ interface Reply<
status: Status,
): OpaqueReply<Op, Status, Content, Headers, Path, ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig>;
}

type OpaqueReply<
Op extends Operation,
Status,
Expand All @@ -239,20 +238,15 @@ type OpaqueReply<
RawReply extends F.RawReplyDefaultExpression<RawServer> = F.RawReplyDefaultExpression<RawServer>,
ContextConfig = F.ContextConfigDefault,
Opaque = Reply<Op, Status, Content, Headers, Path, ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig>
> = Status extends never | unknown
? Opaque
: Content extends never | unknown
? Opaque
: Headers extends never | unknown
? Opaque
: never;
> = Status extends unknown ? Opaque : Content extends unknown ? Opaque : Headers extends unknown ? Opaque : never;

interface Invalid<msg = any> {
readonly __INVALID__: unique symbol;
}

interface AsReply {
readonly __REPLY_SYMBOL__: unique symbol;
then(fulfilled: () => void, rejected: (err: Error) => void): void;
}
const assertAsReply: (any: any) => asserts any is AsReply = () => {};
export const asReply = (any: any) => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultService: Service<TestSchema> = {
},
'GET /empty': async (req, reply) => {
const fastifyReply = reply.status(204);
return fastifyReply;
return fastifyReply.send();
},
};

Expand Down

0 comments on commit a2a143c

Please sign in to comment.