Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

typescript interface with unknown keys

//credit goes to Andrés Reales
interface AllPropertiesString {
  [key: number]: string;
  [key: string]: string;
}

const random: AllPropertiesString = <AllPropertiesString>{};
random[1] = 'This is the value for number 1';
random['1'] = 'This is a string';

console.log(random[1]); // will display 'This is a string'
console.log(random["1"]); // will display 'This is a string'
 
PREVIOUS NEXT
Tagged: #typescript #interface #unknown #keys
ADD COMMENT
Topic
Name
2+6 =