I have a interface for typing that looks like the following
interface Bob{ a: number; b: number; c: number; } However, I don't really want number as any number can be valid. How can I enforce the type of Bob to be numbers strictly in a JSON file like the following.
{ "None": -1, "foo": 22, "moo": 55, "raar": 13, "zaar": 2, "bar": 0, "fooboo": 22, "mooboo": 1000, } That JSON contains around 200 entries hence doing a manual typedef is not optimal.
What I aim to achieve
const myvar: Bob; myvar.a = 2222 // this should throw an error as this number is not defined in the JSON myvar.b = -1 //this is ok as it is in the JSON Thanks!
type values = typeof v[keyof typeof v];(wherevis your imported json)as consttypescriptlang.org/play?#code/…as constdo at the end?