This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
RFC: refactor property signature APIs (e.g. optional
)
#648
Comments
gcanti
added a commit
that referenced
this issue
Dec 10, 2023
gcanti
changed the title
Proposal: refactor property signature APIs (e.g.
RFC: refactor property signature APIs (e.g. Dec 12, 2023
optional
)optional
)
TL;DR but LGTM |
I simplified it a bit by merging all APIs into /*
const schema: S.Schema<{
readonly a: string;
readonly b?: string;
readonly c?: string | undefined;
readonly d?: string;
readonly e?: string | undefined;
readonly f?: string;
readonly g?: string | undefined;
}, {
readonly a: string;
readonly b?: string;
readonly c?: string;
readonly d: Option.Option<string>;
readonly e: Option.Option<string>;
readonly f: string;
readonly g: string;
}>
*/
const schema = S.struct({
a: S.string.pipe(S.propertySignatureAnnotations({ description: "my string" })),
b: S.optional(S.string, { exact: true }),
c: S.optional(S.string),
d: S.optional(S.string, { exact: true, toOption: true }),
e: S.optional(S.string, { toOption: true }),
f: S.optional(S.string, { exact: true, default: () => "" }),
g: S.optional(S.string, { default: () => "" })
}) |
Really glad we're doing breaking api changes with a random voting LGTM 😄 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
This RFC addresses the APIs related to the concept of "optional," specifically the
optional
API in the current version.Main Issues:
optional
API deviates from the standard (API pipeable) as it returns aPropertySignature
interface with two methods, namelytoOption
andwithDefault
.toOption
andwithDefault
address two common use cases, they do not allow the description of other equally common and important use cases.For example, the current implementation cannot express the following transformation:
Proposed Solution:
optional
API tooptionalExact
(reminiscent of exactOptionalPropertyTypes in tsconfig.json).optionalExactToRequired
, which allows transforming an optional field (i.e. marked with the?
modifier) into a required one by specifying transformation modes in both directions (decode
andencode
).Of particular importance is the new primitive
optionalExactToRequired
, which would enable deriving a series of other combinators, as shown in the example snippet below:The text was updated successfully, but these errors were encountered: