TypeScript conditional types and infer
Short answer
type IsString<T> = T extends string ? "yes" : "no";
If the left side is assignable to the right, you get the first branch; otherwise the second. [S1][S2]
Two key tricks
- Conditional types provide us with a way to infer from types we compare against in the true branch using the infer keyword. (S1) U : T;` [S1]
Conditional types are one of several type operators (with keyof, indexed access, mapped and template literal types) for building types from other types. [S2]
Claims
- id: C1 claim: If the left type is assignable, the true branch type is chosen. source: S1 evidence: "When the type on the left of the extends is assignable to the one on"
- id: C2 claim: The infer keyword infers types in the true branch. source: S1 evidence: "infer from types we compare against in the true branch using the infer keyword"
- id: C3 claim: Conditional types distribute over unions given to a generic. source: S1 evidence: "they become distributive when given a union type"
- id: C4 claim: Conditional types act like if statements in the type system. source: S2 evidence: "Types which act like if statements in the type system"
Sources
- [S1] TypeScript: Documentation - Conditional Types. TypeScript (Microsoft). https://www.typescriptlang.org/docs/handbook/2/conditional-types.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-04.
- [S2] TypeScript: Documentation - Creating Types from Types. TypeScript (Microsoft). https://www.typescriptlang.org/docs/handbook/2/types-from-types.html . License: CC BY 4.0 (microsoft/TypeScript-Website). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: TypeScript (Microsoft), TypeScript: Documentation - Conditional Types, CC BY 4.0 (microsoft/TypeScript-Website); TypeScript (Microsoft), TypeScript: Documentation - Creating Types from Types, CC BY 4.0 (microsoft/TypeScript-Website).
Cite this
iinventedlight. 2026. "TypeScript conditional types and infer." iinventedlight Library, iil:note:qzanjw5n, version of 2026-11-04. https://iinventedlight.com/library/notes/typescript-conditional-types/. License: CC-BY-4.0.
@misc{iil_note_qzanjw5n,
author = {{iinventedlight}},
title = {{TypeScript conditional types and infer}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/typescript-conditional-types/},
note = {Permanent ID iil:note:qzanjw5n. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/typescript-conditional-types.md.