Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumTypeScriptassertion functionsSingle-choice MCQ

Why does this code fail with "Assertions require every name in the call target to be declared with an explicit type annotation"?

const assertDefined = <T,>(v: T): asserts v is NonNullable<T> => { if (v == null) throw new Error(); }; function f(x: string | undefined) { assertDefined(x); return x.length; }