Comparing satisfies, type annotations, and assertions through compiler output
Use satisfies when a configuration value should meet a type while its individual properties remain convenient to use. Two common shortcuts are misleading, though: that it can never affect inference, and that it always rejects extra keys. The comparison uses the same object under a type annotation, satisfies , and as , with emitted declarations and diagnostics as evidence. For this display…
Satisfies, type annotations, and assertions all serve distinct purposes when working with TypeScript, and their compiler outputs illustrate those differences. The experiment, conducted on September 11, 2026, used Node.js 24.15.0, TypeScript 7.0.2, and macOS arm64 to compare the three concepts.
The first example defined a type `Notices` with properties `ready` and `waiting`, which could be either a string or an array of numbers. Three variables were then created: `annotated`, `checked`, and `asserted`, each using a different approach to specifying the type of the object. While `annotated` used type annotations, `checked` employed `satisfies`, and `asserted` utilized an assertion.
When accessing the `ready` property of `checked`, the compiler successfully called the `toUpperCase()` method, indicating that the property exists and is of the expected type. However, attempting the same operation on `annotated` triggered a type error, as the compiler recognized that `ready` could also be an array of numbers, not just a string.
The emitted declarations revealed that `checked` retained the types of individual properties, while `annotated` and `asserted` shared the same `Notices` type. This behavior highlights the usefulness of `satisfies` when a configuration needs compatibility checks without requiring additional narrowing when working with specific properties.
Next, the experiment explored assertions with a similar `Notices` type. When creating a value object with only the `ready` property, the compiler did not detect the missing `waiting` property when using an assertion. However, switching to `satisfies` produced a type error for the missing property, demonstrating that assertions are more permissive than `satisfies` in terms of required properties.
Finally, the experiment showcased the impact of context on inference. Using `as const` on an object with `enabled` and `count` properties resulted in those properties being inferred as `true` and `number`, respectively. When employing `frozenType` with `as const`, the `enabled` property became a readonly `true`, and `count` became a readonly `1`. This showcases how contextual information can lead to different inferred types for the same object.
In conclusion, the experiment revealed that `satisfies` is valuable for compatibility checks, type annotations offer explicit property types, and assertions provide a more permissive approach when certain properties are optional. Understanding these distinctions and their compiler outputs is crucial for effectively working with TypeScript's type system.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.