Skip to content

Commit c627ad5

Browse files
committed
chore: enable strictNullChecks
1 parent 0160ba9 commit c627ad5

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/build/nodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function typeAliasDeclaration(name: string, node: TypeNode, exported: boo
8484
return f.createTypeAliasDeclaration(exported ? [exportToken()] : [], name, types, node);
8585
}
8686

87-
export function typeParameterDeclaration(name: string, constraint: TypeNode = undefined, def: TypeNode = undefined) {
87+
export function typeParameterDeclaration(name: string, constraint?: TypeNode, def?: TypeNode) {
8888
return f.createTypeParameterDeclaration(undefined, name, constraint, def);
8989
}
9090

lib/types.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,25 @@ export type ResponseType<R extends Route> = R["settings"]["response"];
118118
/**
119119
* Get the response body type for a route (this is likely a union)
120120
*/
121-
export type BodyType<R extends Route> = R["settings"]["response"]["body"];
121+
export type BodyType<R extends Route> = "body" extends keyof R["settings"]["response"]
122+
? R["settings"]["response"]["body"]
123+
: unknown;
122124
/**
123125
* Get the response type for a route matching a specific status code
124126
*/
125-
export type SpecificResponseType<R extends Route, S extends StatusCode = StatusCode> = Extract<R["settings"]["response"], { status: S }>;
127+
export type SpecificResponseType<R extends Route, S extends StatusCode = StatusCode> = R["settings"]["response"] extends { status: S }
128+
? R["settings"]["response"]
129+
: "status" extends keyof R["settings"]["response"]
130+
? S extends R["settings"]["response"]["status"]
131+
? R["settings"]["response"]
132+
: RouteSettings["response"]
133+
: RouteSettings["response"];
126134
/**
127135
* Get the response body type for a route matching a specific status code
128136
*/
129-
export type SpecificBodyType<R extends Route, S extends StatusCode = StatusCode> = SpecificResponseType<R, S>["body"];
137+
export type SpecificBodyType<R extends Route, S extends StatusCode = StatusCode> = "body" extends keyof SpecificResponseType<R, S>
138+
? SpecificResponseType<R, S>["body"]
139+
: unknown;
130140

131141
/**
132142
* Get a list of all available paths for a given method on a route union

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"module": "nodenext",
1111
"target": "esnext",
1212
"skipLibCheck": true,
13+
"strictNullChecks": true,
1314
"allowImportingTsExtensions": true,
1415
"verbatimModuleSyntax": true,
1516
"erasableSyntaxOnly": true,

0 commit comments

Comments
 (0)