{"record":{"id":"cc413bd95ec4ac03","repo":"colinhacks/zod","slug":"invalid-template-literal-part-no-pattern-found","errorCode":null,"errorMessage":"Invalid template literal part, no pattern found: ${[...(part as any)._zod.traits].shift()}","messagePattern":"Invalid template literal part, no pattern found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/zod/src/v4/core/schemas.ts","lineNumber":4315,"sourceCode":"export type $PartsToTemplateLiteral<Parts extends $ZodTemplateLiteralPart[]> = [] extends Parts\n  ? ``\n  : Parts extends [...infer Rest, infer Last extends $ZodTemplateLiteralPart]\n    ? Rest extends $ZodTemplateLiteralPart[]\n      ? AppendToTemplateLiteral<$PartsToTemplateLiteral<Rest>, Last>\n      : never\n    : never;\n\nexport const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__PURE__*/ core.$constructor(\n  \"$ZodTemplateLiteral\",\n  (inst, def) => {\n    $ZodType.init(inst, def);\n    const regexParts: string[] = [];\n    for (const part of def.parts) {\n      if (typeof part === \"object\" && part !== null) {\n        // is Zod schema\n        if (!part._zod.pattern) {\n          // if (!source)\n          throw new Error(`Invalid template literal part, no pattern found: ${[...(part as any)._zod.traits].shift()}`);\n        }\n\n        const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;\n\n        if (!source) throw new Error(`Invalid template literal part: ${part._zod.traits}`);\n\n        const start = source.startsWith(\"^\") ? 1 : 0;\n        const end = source.endsWith(\"$\") ? source.length - 1 : source.length;\n        regexParts.push(source.slice(start, end));\n      } else if (part === null || util.primitiveTypes.has(typeof part)) {\n        regexParts.push(util.escapeRegex(`${part}`));\n      } else {\n        throw new Error(`Invalid template literal part: ${part}`);\n      }\n    }\n    inst._zod.pattern = new RegExp(`^${regexParts.join(\"\")}$`);\n\n    inst._zod.parse = (payload, _ctx) => {","sourceCodeStart":4297,"sourceCodeEnd":4333,"githubUrl":"https://github.com/colinhacks/zod/blob/2d90846af918af9602e088812d63a035d47cdbe4/packages/zod/src/v4/core/schemas.ts#L4297-L4333","documentation":"Thrown by the $ZodTemplateLiteral constructor while iterating def.parts when a part is an object (treated as a Zod schema) but has no _zod.pattern. Template literals build a single regex by concatenating each part's pattern; a schema part without a pattern (e.g. z.any(), z.unknown(), z.never(), z.void(), or a non-string schema that never publishes a pattern) cannot contribute a regex fragment. The message prints the first trait of the offending part to help identify its type.","triggerScenarios":"Calling z.template`${z.any()}`, z.template`${z.unknown()}`, or embedding a schema that does not expose _zod.pattern (transforms whose output has no pattern, some object/array schemas, or custom schemas missing a pattern).","commonSituations":"Composing a template from user-supplied schemas without checking they are pattern-bearing; upgrading a schema in the template to one without a pattern; using z.lazy() or z.custom() whose resolved schema lacks a pattern; passing a non-string primitive-wrapper by mistake.","solutions":["Use only string-pattern-producing schemas in the template: z.string(), z.number(), z.literal(), z.uuid(), z.date(), z.enum(), or nested z.template`...`.","Replace z.any()/z.unknown() with z.string() or another patterned primitive.","For custom schemas, assign inst._zod.pattern in the constructor so the template can consume it.","If a non-patterned schema is essential, pre-compute its string fragment and inline it as a plain string part."],"exampleFix":"// before\nconst T = z.template`${z.any()}-${z.number()}`;\n// after\nconst T = z.template`${z.string()}-${z.number()}`;","handlingStrategy":"type-guard","validationCode":"function isPatterned(part: unknown): boolean {\n  return typeof part === \"object\" && part !== null && !!(part as any)?._zod?.pattern;\n}","typeGuard":"function isPatterned(part: unknown): boolean {\n  return typeof part === \"object\" && part !== null && !!(part as any)?._zod?.pattern;\n}","tryCatchPattern":null,"preventionTips":["Use only pattern-producing schemas (z.string, z.number, z.literal, z.uuid, z.date, z.enum) inside z.template`...`.","Avoid z.any()/z.unknown()/z.never() in templates.","For custom schemas, assign inst._zod.pattern in the constructor."],"tags":["template-literal","schema-construction","regex","pattern"],"backgroundTag":null,"analyzedSha":"2d90846af918af9602e088812d63a035d47cdbe4","analyzedAt":"2026-08-11T01:21:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}