Can decorators be utilized to add custom information to specific properties within an interface?
An example can help clarify this:
Interface for App state:
export interface AppState {
@persist userData: UserData,
@persist selectedCompany: UserCompany,
// userCompanies should not be persisted since they are always
// fetched afresh from the server...
userCompanies: UserCompany[]
}
Function for persisting relevant state information:
persistState(state) {
let newState = {};
Object.keys(state).forEach((key) => {
if (state[key] is marked with @persist) {
newState[key] = state[key];
}
});
// Persist newState...
}
Is it feasible to achieve this using decorators?
Any guidance or resources on how to implement this would be greatly appreciated!
If it's not possible, are there any other elegant solutions available?