MCPcopy Create free account
hub / github.com/Effect-TS/effect / getExpected

Method getExpected

packages/effect/src/SchemaAST.ts:2921–2956  ·  view source on GitHub ↗

@internal

(getExpected: (ast: AST) => string)

Source from the content-addressed store, hash-verified

2919 }
2920 /** @internal */
2921 getExpected(getExpected: (ast: AST) => string): string {
2922 const expected = this.annotations?.expected
2923 if (typeof expected === "string") return expected
2924
2925 if (this.types.length === 0) return "never"
2926
2927 const types = this.types.map((type) => {
2928 const encoded = toEncoded(type)
2929 switch (encoded._tag) {
2930 case "Arrays": {
2931 const literals = encoded.elements.filter(isLiteral)
2932 if (literals.length > 0) {
2933 return `${formatIsMutable(encoded.isMutable)}[ ${
2934 literals.map((e) => getExpected(e) + formatIsOptional(e.context?.isOptional)).join(", ")
2935 }, ... ]`
2936 }
2937 break
2938 }
2939 case "Objects": {
2940 const literals = encoded.propertySignatures.filter((ps) => isLiteral(ps.type))
2941 if (literals.length > 0) {
2942 return `{ ${
2943 literals.map((ps) =>
2944 `${formatIsMutable(ps.type.context?.isMutable)}${formatPropertyKey(ps.name)}${
2945 formatIsOptional(ps.type.context?.isOptional)
2946 }: ${getExpected(ps.type)}`
2947 ).join(", ")
2948 }, ... }`
2949 }
2950 break
2951 }
2952 }
2953 return getExpected(encoded)
2954 })
2955 return Array.from(new Set(types)).join(" | ")
2956 }
2957}
2958
2959function failSingleUnionCandidate(

Callers

nothing calls this directly

Calls 7

formatPropertyKeyFunction · 0.90
toEncodedInterface · 0.85
formatIsMutableFunction · 0.85
formatIsOptionalFunction · 0.85
filterMethod · 0.80
joinMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected