I'm trying to implement a method like that takes a key argument that is either a string
or an instance of the indexable type interface IValidationContextIndex
. The implementation looks like this:
/**
* Gets all ValidationContext container values.
* @returns An array of ValidationContext instances contained in the cache.
*/
public static getValidationContextValues(key: IValidationContextIndex | string ): Array<ValidationContext> {
if (key instanceof IValidationContextIndex ) [
return Object.values(<any> key);
]
else {
const vci = ValidationContainer.cache[<string>key];
return Object.values(<any> vci);
}
}
Typescript give the following error for the if
block:
[ts] 'IValidationContextIndex' only refers to a type, but is being used as a value here.
Any ideas on how to fix this?
For most interface I think it's possible to add a type
property ( type: 'IValidationContextsIndex'
;
), but that does not work in this case since the the interface is an indexable type interface ....