I have the following JSON which I have no control over:
{
"date": "2020-01-01T00:00:00",
"a": 0,
"b": 0,
"c": 0
}
Instead of specifying an interface:
interface Foo {
date: Date,
"a": number,
"b": number,
"c": number
}
I want to be able to statically type the payload like so:
type Age = "a";
type Salary = "b";
type Height = "c"
type Foo = Record<"date", Date> | Record<Age | Salary | Height, number>;
Even though the compiler seems happy but when I try to get the date from the object I get the following error:
const foo = {
"date": "2020-01-01T00:00:00",
"a": 0,
"b": 0,
"c": 0
} as Foo;
Element implicitly has 'any' type.
If I remove the Record<Age | Salary | Height, number> then the error goes away.
anytype ?