Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

can ts object be strongly typed?

// This defines an interface that only allows values to be numbers
interface INumbersOnly {
  [key: string]: number;
}

// when using it, it will check that all properties are numbers
var x: INumbersOnly = {
  num: 1, // works fine
  str: 'x' // will give a type error
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #ts #object #strongly
ADD COMMENT
Topic
Name
5+9 =