Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

use array element as types

const arrayWithAllFruitsAsvalues = ['apple', 'peach'] as const;

type Fruit = typeof arrayWithAllFruitsAsvalues[number];  // "apple" | "peach"

const objectWithAllFruitsAsKeys: {
  [ key in Fruit ]: any
} = { apple: '', peach: '' }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #array #element #types
ADD COMMENT
Topic
Name
2+8 =