TypeScript 3.7 has this new cool feature which enables us to write "assertion functions". For example, here is one of mine:
export type TOfferAttrName = keyof typeof offerAttrMap;
export const assertIsOfferAttrName = (name: string): asserts name is TOfferAttrName => {
if (!Object.prototype.hasOwnProperty.call(offerAttrMap, name)) {
throw new Error('It is required that property name is an allowed one');
}
};
The problem is that there is nothing forcing me to write a correct assertion function. I can pretty much just omit the whole body of the function and TS will be perfectly happy with it. Thus it is quite equal to just optimistically typecasting with as.
Am I missing something and is there a way for TS to actually force me to write a correct assertion function?