File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -152,8 +152,7 @@ export function loadTestSettingsFromUrl(getOverride?: string): void {
152152 let de : SharedTestSettings ;
153153 try {
154154 const decompressed = decompressFromURI ( getValue ) ?? "" ;
155- const parsed = parseJsonWithSchema ( decompressed , TestSettingsSchema ) ;
156- de = parsed as SharedTestSettings ; // Assign after refinement
155+ de = parseJsonWithSchema ( decompressed , TestSettingsSchema ) ;
157156 } catch ( e ) {
158157 console . error ( "Failed to parse test settings:" , e ) ;
159158 Notifications . add (
Original file line number Diff line number Diff line change 1- import { ZodError , ZodIssue , ZodSchema } from "zod" ;
1+ import { z , ZodError , ZodIssue } from "zod" ;
22
33/**
44 * Parse a JSON string into an object and validate it against a schema
55 * @param json JSON string
66 * @param schema Zod schema to validate the JSON against
77 * @returns The parsed JSON object
88 */
9- export function parseWithSchema < T > ( json : string , schema : ZodSchema < T > ) : T {
9+ export function parseWithSchema < T extends z . ZodTypeAny > (
10+ json : string ,
11+ schema : T
12+ ) : z . infer < T > {
1013 try {
1114 const jsonParsed = JSON . parse ( json ) as unknown ;
12- const zodParsed = schema . parse ( jsonParsed ) ;
13- return zodParsed ;
15+ // hits is fine to ignore
16+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
17+ return schema . parse ( jsonParsed ) as z . infer < T > ;
1418 } catch ( error ) {
1519 if ( error instanceof ZodError ) {
1620 throw new Error ( error . issues . map ( prettyErrorMessage ) . join ( "\n" ) ) ;
You can’t perform that action at this time.
0 commit comments