schema-components - v3.7.0
    Preparing search index...

    Type Alias FromJSONSchema<S, Defs, Depth, Mode>

    FromJSONSchema: MergeRootDefs<S, Defs> extends infer MergedDefs extends
        Record<string, unknown>
        ? S extends { nullable: true }
            ? FromJSONSchema<Omit<S, "nullable">, MergedDefs, Depth, Mode> | null
            : S extends { $ref: infer R extends string }
                ? ResolveSchemaRef<R, MergedDefs, Depth, Mode>
                : S extends { $recursiveRef: string }
                    ? unknown
                    : S extends { $dynamicRef: infer R extends string }
                        ? ResolveSchemaRef<R, MergedDefs, Depth, Mode>
                        : S extends { allOf: infer A }
                            ? AllOfToType<A, MergedDefs, Depth, Mode>
                            : S extends { anyOf: infer A }
                                ? UnionOfMembers<A, MergedDefs, Depth, Mode>
                                : S extends {
                                    oneOf: infer A;
                                    discriminator: { propertyName: infer DP extends (...) };
                                }
                                    ? DiscriminatedOneOfToUnion<
                                        A,
                                        DP,
                                        GetDiscriminatorMapping<S>,
                                        MergedDefs,
                                        Depth,
                                        Mode,
                                    >
                                    : S extends { oneOf: infer A }
                                        ? UnionOfMembers<A, MergedDefs, Depth, Mode>
                                        : S extends { if: ... }
                                            ? FromJSONSchema<(...), (...), (...), (...)>
                                            : (...) extends (...) ? (...) : (...)
        : unknown

    Maps a JSON Schema structure to a TypeScript type. Works with as const literals -- provides full autocomplete for fields.

    Supports all JSON Schema draft versions (04-2020-12) and OpenAPI 3.x:

    • Primitive types: string, number, integer, boolean, null
    • type as array: ["string", "null"] -> string | null (nullable)
    • enum -> union of literal types
    • const -> literal type
    • object with properties/required -> specific object type
    • object with properties + additionalProperties -> object & Record<string, V>
    • object with additionalProperties only -> Record<string, T>
    • array with items -> T[]
    • array with prefixItems -> tuple type
    • allOf -> intersection type
    • anyOf -> union type
    • oneOf -> union type (plain union, or tagged union when discriminator is set)
    • $ref -> resolved via $defs/definitions/$anchor context
    • $dynamicRef -> resolved via $dynamicAnchor in definitions
    • $recursiveRef -> unknown (recursive types not expressible in TS)
    • if/then/else -> base schema (conditionals not expressible in TS)
    • not -> unknown (negation not expressible in TS)
    • patternProperties -> merged into loose index signature

    The Mode parameter controls how readOnly / writeOnly keywords influence inferred object properties — see FromJSONSchemaMode.

    Type Parameters

    • S
    • Defs extends Record<string, unknown> = Record<string, never>
    • Depth extends readonly unknown[] = []
    • Mode extends FromJSONSchemaMode = "both"