Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

get key value typescript

const getKeyValue =
  <T extends object, U extends keyof T>(obj: T) =>
  (key: U) => {
    return obj[key]
  }
  
// Usage
const list = {
  1: '1',
  2: '2',
  3: '3',
}

getKeyValue(list)(2)
 
PREVIOUS NEXT
Tagged: #key #typescript
ADD COMMENT
Topic
Name
5+6 =