API reference › @evolu/common › Type › templateLiteral
function templateLiteral<Parts>(
...parts: {
readonly [Index in string | number | symbol]: ValidateTemplateLiteralPart<
Parts[Index]
>;
} & TemplateLiteralValidation<Parts>
): TemplateLiteralType<Parts>;
Defined in: packages/common/src/Type.ts:4442
Template literal Type for validation.
Creates a canonical string Type from fixed strings and string-encoded Types.
Use this factory when Output should remain a string. Switch to templateLiteralParser when the individual Type parts should be decoded into a Tuple.
Example
import {
assertFalse,
assertOk,
assertType,
templateLiteral,
union,
} from "@evolu/common";
const Language = union("en", "cs");
const Region = union("US", "CZ");
const Locale = templateLiteral(Language, "-", Region);
assertType<"en-US" | "en-CZ" | "cs-US" | "cs-CZ", typeof Locale.Output>();
assertOk(Locale.fromUnknown("cs-CZ"), "cs-CZ");
assertFalse(Locale.is("fr-CZ"));