---
source: https://iinventedlight.com/library/notes/typescript-conditional-types.md
title: "TypeScript conditional types and infer"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (microsoft/TypeScript-Website); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: TypeScript"
tags: typescript, types, conditional-types, generics
sources:
  - id: S1
    title: "TypeScript: Documentation - Conditional Types"
    publisher: TypeScript (Microsoft)
    url: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
    accessed: 2026-11-04
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
  - id: S2
    title: "TypeScript: Documentation - Creating Types from Types"
    publisher: TypeScript (Microsoft)
    url: https://www.typescriptlang.org/docs/handbook/2/types-from-types.html
    accessed: 2026-11-04
    license: "CC BY 4.0 (microsoft/TypeScript-Website)"
---
# TypeScript conditional types and infer

## Short answer

```ts
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).
