← All notes

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 are one of several type operators (with keyof, indexed access, mapped and template literal types) for building types from other types. [S2]

Claims

Sources

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

Permanent ID: iil:note:qzanjw5n

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.},
}

Markdown

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.