Challenges with Parsing Query Strings and 3rd Party Type from 'qs'
I'm trying to write a schema for parsing query strings, and I'm getting stuck dealing with the 3rd party type from
gives the following error:
Is there maybe a better way to do this, or to work around the problem of
qsqs:import qs from "qs";
import * as Schema from "@effect/schema/Schema";
const ParsedQs: Schema.Schema<qs.ParsedQs> = Schema.lazy(() =>
Schema.record(
Schema.string,
Schema.union(
Schema.undefined,
Schema.string,
Schema.array(Schema.string),
ParsedQs,
Schema.array(ParsedQs)
)
)
);
const parsedQsFromString = Schema.transform(
Schema.string,
ParsedQs,
(input) => qs.parse(input),
(output) => qs.stringify(output)
);
export const fromQueryStringParameters = <A>(schema: Schema.Schema<any, A>) =>
Schema.struct({
rawQueryString: Schema.compose(parsedQsFromString, schema),
});import qs from "qs";
import * as Schema from "@effect/schema/Schema";
const ParsedQs: Schema.Schema<qs.ParsedQs> = Schema.lazy(() =>
Schema.record(
Schema.string,
Schema.union(
Schema.undefined,
Schema.string,
Schema.array(Schema.string),
ParsedQs,
Schema.array(ParsedQs)
)
)
);
const parsedQsFromString = Schema.transform(
Schema.string,
ParsedQs,
(input) => qs.parse(input),
(output) => qs.stringify(output)
);
export const fromQueryStringParameters = <A>(schema: Schema.Schema<any, A>) =>
Schema.struct({
rawQueryString: Schema.compose(parsedQsFromString, schema),
});gives the following error:
error TS2322: Type 'Schema<{ readonly [x: string]: string | readonly string[] | ParsedQs | readonly ParsedQs[] | undefined; }, { readonly [x: string]: string | readonly string[] | ParsedQs | readonly ParsedQs[] | undefined; }>' is not assignable to type 'Schema<ParsedQs, ParsedQs>'.
The types returned by 'From(...)' are incompatible between these types.
Type '{ readonly [x: string]: string | readonly string[] | ParsedQs | readonly ParsedQs[] | undefined; }' is not assignable to type 'ParsedQs'.
65 const ParsedQs: Schema.Schema<qs.ParsedQs> = Schema.lazy(() =>
~~~~~~~~error TS2322: Type 'Schema<{ readonly [x: string]: string | readonly string[] | ParsedQs | readonly ParsedQs[] | undefined; }, { readonly [x: string]: string | readonly string[] | ParsedQs | readonly ParsedQs[] | undefined; }>' is not assignable to type 'Schema<ParsedQs, ParsedQs>'.
The types returned by 'From(...)' are incompatible between these types.
Type '{ readonly [x: string]: string | readonly string[] | ParsedQs | readonly ParsedQs[] | undefined; }' is not assignable to type 'ParsedQs'.
65 const ParsedQs: Schema.Schema<qs.ParsedQs> = Schema.lazy(() =>
~~~~~~~~Is there maybe a better way to do this, or to work around the problem of
qs.ParsedQsqs.ParsedQs properties not being readonlyreadonly? 