I have some code similar to the following and TypeScript complains about the property __cache
:
Property '__cache' does not exist on type '() => number'.(2339)
function getNextValue(): number {
if (typeof getNextValue.__cache === 'undefined') {
getNextValue.__cache = 0;
}
return ++getNextValue.__cache;
}
How can this be correctly typed to declare a property __cache: number|undefined
?