I am facing an issue with the code below:
options: { url?: string } = {};
if (!Checker.present(this.options.url)) {
throw new Error('Options must have a url');
}
new CustomUrl(this.options)
This error is occurring because CustomUrl
requires a url, but my interface has made it optional.
The function I use for checking looks like this:
static present(value: any) {
return value !== undefined && value !== null;
}
However, I am unsure how to communicate to TypeScript that I have checked and confirmed the presence of a value without using the !
operator in my code. Any suggestions?