TypeScript Concepts
Type soundness — static guarantees and exceptions
TypeScript intentionally permits some operations that can invalidate static assumptions. For instance a mutable array of narrower elements can be assigned to a wider array, then modified through that alias. The example deliberately demonstrates the mismatch without crashing; it is not recommended code. Readonly consumers and runtime checks help at boundaries but do not make the language fully sound. Observed output: 'undefined'. 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
const view: Animal[] = dogs;Working Example
Example Snippettypescript
type Animal = { name: string };type Dog = Animal & { bark(): void };const dogs: Dog[] = [{ name: "Pip", bark() {} }];const animals: Animal[] = dogs;animals.push({ name: "Moss" });console.log(typeof dogs[1].bark);