I want to pass an assertion function as a named argument and invoke it. TypeScript complains when I try this:
const myFunc = ({ myAssertionFunc }: { myAssertionFunc: (x: unknown) => asserts x is string }) => {
myAssertionFunc(1234); // "Assertions require every name in the call target to be declared with an explicit type annotation. ts(2775)"
}
But a positional argument works:
const myFunc = (myAssertionFunc: (x: unknown) => asserts x is string) => {
myAssertionFunc(1234); // No compile-time problem!
}
Am I doing this incorrectly? Or is this a missing feature in TypeScript?