# Using branded types in validators

DevFeed: [Using branded types in validators](<https://devfeed.tech/articles/using-branded-types-in-validators-81483.md>)

Original publisher: [Read original article](<https://stack.convex.dev/using-branded-types-in-validators>)

Author: Stack

Published: 2024-01-20T03:31:33Z

Content type: tutorial

Language: en

Sources: [Stack](<https://devfeed.tech/sources/stack.md>)

Topics: [Programming language](<https://devfeed.tech/topics/programming-language.md>), [Data validation](<https://devfeed.tech/topics/data-validation.md>), [Structured-data](<https://devfeed.tech/topics/structured-data.md>)

Tags: [convex](<https://devfeed.tech/tags/convex.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [schema](<https://devfeed.tech/tags/schema.md>)

## AI overview

The tutorial explains how to use TypeScript branded string types with Convex validators. It shows defining a branded type, applying it in schema fields and function arguments, and using casts so TypeScript can check those types while runtime validation remains based on the underlying string validator. It also cautions that unsafe casts can create mismatches between compile-time types and runtime validation.

## Source excerpt

If you have a more specific type than what you can express with Convex validators, you can still document that at the type level in Convex by casting once in your schema definition.