Here's a quick demo of using a set of Enums to derive a full Description for a Lookup value when only the Identifier was provided. Code is a copy/paste from TypeScript Playground for ease of testing
// String Enum Example using the TypeScript Playground example for test purposes
// Test here: https://www.typescriptlang.org/play/
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet(skip = false) {
let skipMessage = null;
if (skip) {
skipMessage = ' Skip';
}
return `${this.greeting}`;
}
}
// Status Type Identifiers (What we might get from an Api)
enum StatusTypeIds {
Submitted = 0,
Processing = 1,
OnHold = 2
}
// Status Type Descriptions
enum StatusTypes {
Submitted = 'Submitted',
Processing = 'Processing',
OnHold = 'On Hold for further investigation'
}
// Derive the StatusTypeId from the provided value
const statusTypeId = StatusTypeIds[2];
// Use the derived Enum value to retrieve the associated Description
const statusDescription = StatusTypes[statusTypeId];
let greeter = new Greeter(statusDescription);
let button = document.createElement('button');
button.textContent = "Status";
button.onclick = function() {
alert(greeter.greet(true));
}
document.body.appendChild(button);