TypeScript Concepts

Excess property checks — fresh object literals

When a fresh object literal is checked against an object contract, unexpected properties can cause a diagnostic. An already typed variable with extra properties can often be assigned structurally. This catches likely misspellings but does not establish exact shapes or remove extra runtime fields. Observed output: 'true 2'. 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 options: Options = { known: true };

Working Example

Example Snippettypescript
type Options = { enabled: boolean };const config = { enabled: true, label: "local" };const selected: Options = config;console.log(selected.enabled, Object.keys(selected).length);
TypeScript Reference