MCPcopy Index your code
hub / github.com/Effect-TS/effect / partial

Function partial

packages/effect/src/SchemaAST.ts:2500–2537  ·  view source on GitHub ↗
(ast: AST, options?: { readonly exact: true })

Source from the content-addressed store, hash-verified

2498 * @since 3.10.0
2499 */
2500export const partial = (ast: AST, options?: { readonly exact: true }): AST => {
2501 const exact = options?.exact === true
2502 switch (ast._tag) {
2503 case "TupleType":
2504 return new TupleType(
2505 ast.elements.map((e) => new OptionalType(exact ? e.type : orUndefined(e.type), true)),
2506 Arr.match(ast.rest, {
2507 onEmpty: () => ast.rest,
2508 onNonEmpty: (rest) => [new Type(Union.make([...getRestASTs(rest), undefinedKeyword]))]
2509 }),
2510 ast.isReadonly
2511 )
2512 case "TypeLiteral":
2513 return new TypeLiteral(
2514 ast.propertySignatures.map((ps) =>
2515 new PropertySignature(ps.name, exact ? ps.type : orUndefined(ps.type), true, ps.isReadonly, ps.annotations)
2516 ),
2517 ast.indexSignatures.map((is) => new IndexSignature(is.parameter, orUndefined(is.type), is.isReadonly))
2518 )
2519 case "Union":
2520 return Union.make(ast.types.map((member) => partial(member, options)))
2521 case "Suspend":
2522 return new Suspend(() => partial(ast.f(), options))
2523 case "Declaration":
2524 case "Refinement":
2525 throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2526 case "Transformation": {
2527 if (
2528 isTypeLiteralTransformation(ast.transformation) &&
2529 ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)
2530 ) {
2531 return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation)
2532 }
2533 throw new Error(errors_.getASTUnsupportedSchemaErrorMessage(ast))
2534 }
2535 }
2536 return ast
2537}
2538
2539/**
2540 * Equivalent at runtime to the built-in TypeScript utility type `Required`.

Callers

nothing calls this directly

Calls 5

orUndefinedFunction · 0.85
getRestASTsFunction · 0.85
mapMethod · 0.65
makeMethod · 0.65
fMethod · 0.65

Tested by

no test coverage detected