Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
TypeScript Data structure for indexed actions table

I have a series of roles with ascending permissions. I also have series of issue states. I expect both of these to be represented as TypeScript enums.

I wish to provide a series of available actions, for different roles, for issues in different states: enter image description here

I have a couple of related challenges.

  1. I wish to have a data structure where the role/issue-state are indexed by TS enums
  2. I wish to be able to store data in the structure in a legible manner (for easy review by a domain expert), like below
actions[engineer][newReqest] = ["Claim"]
actions[engineer][liveRequest] = ["Submit for review"]
  1. When determining the actions for the current role ("Manager") I should be able to retrieve the inferred actions for the lower roles too ("Engineer" and "Team Lead")

Can anybody point me to the TypeScript object type that best suits the above scenario?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I've attempted a solution in a playground. I supports the domain-expert-legible assignment, but I have some remaining TS errors. It could probably be improved...

enum Roles {
  Engineer,
  TeamLeader,
  Manager
}

enum IssueStates {
  New,
  Live,
  Closed
}

const actions = []
actions[IssueStates.New] = []
actions[IssueStates.Live] = []
actions[IssueStates.Closed] = []
actions[IssueStates.New][Roles.Engineer] = ["Claim"]
actions[IssueStates.Live][Roles.Engineer] = ["Submit"]
actions[IssueStates.Live][Roles.TeamLeader] = ["Accept", "Reject"]
actions[IssueStates.Closed][Roles.Manager] = ["ReOpen"]

const actionsFor = (tblActions: any, state: IssueStates, role: Roles): Array<String> => {
  const forState = tblActions[state]
  const actions = forState.filter((element: any, index: number) => index <= role)
  return actions.flat(2) || []
}

console.log("Team leader for live issue", actionsFor(actions, IssueStates.Live, Roles.TeamLeader))
console.log("Team leader for closed issue", actionsFor(actions, IssueStates.Closed, Roles.TeamLeader))
console.log("Manager for closed issue", actionsFor(actions, IssueStates.Closed, Roles.Manager))

let summary = ""
for(let state in IssueStates) {
  if(!isNaN(+state)) {
    for(let role in Roles) {
      if(!isNaN(+role)) {
        summary += state + ", " + role  + ", " + actionsFor(actions, state, role) + "\n"
      }
    }
  }
}
console.log("Summary",  "\n", summary)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!