TypeScript Concepts

Bivariance — method parameter exception

Bivariant comparison can accept parameter assignments in either subtype direction. Method parameter positions are exempt from strictFunctionTypes contravariance in the usual structural comparison. This compatibility concession may admit an unsafe caller; prefer function-valued properties when narrower consumers must be rejected. Observed output: 'Pip'. Local example verified with TypeScript 5.8.3, strict checking, ES2022/CommonJS and Node.js 22.16.0; declarations enabled.

Formal Syntax & Structure

typescript syntaxtypescript
interface Handler<T> { handle(value: T): void }

Working Example

Example Snippettypescript
type Animal = { name: string };type Dog = Animal & { bark(): void };interface Handler<T> { handle(value: T): void }const dog: Handler<Dog> = { handle(d) { console.log(d.name); d.bark(); } };const broad: Handler<Animal> = dog;broad.handle({ name: "Pip", bark() {} } as Dog);
TypeScript Reference