Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript keyof typeof

enum ColorsEnum {
    white = '#ffffff',
    black = '#000000',
}

type Color = keyof typeof ColorsEnum; // 'white' | 'black'

let colorLiteral: Color
colorLiteral = "white"  // OK
colorLiteral = "black"  // OK
colorLiteral = "red"    // Error...
 
PREVIOUS NEXT
Tagged: #typescript #keyof #typeof
ADD COMMENT
Topic
Name
7+4 =