Answers for "can ts object be strongly typed?"

0

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
};
Posted by: Guest on January-11-2022

Code answers related to "TypeScript"

Browse Popular Code Answers by Language