Type compatibility and structural typing
Answer: Languages like C# and Java use nominal typing instead.
Example
interface Pet { name: string }
class Dog { name = "Rex"; bark() {} }
let p: Pet = new Dog(); // OK: Dog has name
Rules of thumb
- Return types: the source must return at least what the target promises.
- Private and protected class members make compatibility depend on the declaring class.
Building types from types
Because compatibility is about shape, TypeScript offers operators to derive shapes: keyof, typeof, indexed access, conditional types, mapped types and template literal types.
type Keys = keyof Pet; // "name"
type ReadonlyPet = { readonly [K in keyof Pet]: Pet[K] };
Claims
- id: C1 claim: Structural typing relates types based solely on their members. source: S1 evidence: "Structural typing is a way of relating types based solely on their members."
- id: C2 claim: This is in contrast with nominal typing. source: S1 evidence: "This is in contrast with nominal typing."
- id: C3 claim: In C# or Java the equivalent code would be an error. source: S1 evidence: "In nominally-typed languages like C# or Java, the equivalent code would be an error"
- id: C4 claim: TypeScript offers mapped types. source: S2 evidence: "Mapped Types"
- id: C5 claim: TypeScript offers conditional types. source: S2 evidence: "Conditional Types"
Sources
- [S1] TypeScript: Documentation - Type Compatibility. TypeScript (Microsoft). https://www.typescriptlang.org/docs/handbook/type-compatibility.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 - Type Compatibility, 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. "Type compatibility and structural typing." iinventedlight Library, iil:note:20z5qj5r, version of 2026-11-04. https://iinventedlight.com/library/notes/typescript-type-compatibility/. License: CC-BY-4.0.
@misc{iil_note_20z5qj5r,
author = {{iinventedlight}},
title = {{Type compatibility and structural typing}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/typescript-type-compatibility/},
note = {Permanent ID iil:note:20z5qj5r. 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-type-compatibility.md.