The value to check
true if the value implements IAttributeContainer interface, false otherwise
const container = createAttributeContainer(config, "test-container");
if (isAttributeContainer(container)) {
// TypeScript now knows container is IAttributeContainer
console.log(container.size);
container.set("key", "value");
}
// Check unknown object
function processContainer(obj: unknown) {
if (isAttributeContainer(obj)) {
obj.forEach((key, value) => console.log(key, value));
}
}
Helper function to identify if a passed argument is or implements the IAttributeContainer interface