I am currently working on defining a type to represent a list (hash) of HTTP headers. This type is supposed to be a hash that only contains key / string pairs:
type TStringStringHash = {
[key: string]: string
}
However, the issue I am facing is that it allows an empty object of type TStringStringHash
to be created:
const foo: TStringStringHash = {}
In my implementation, having an empty object like this doesn't make sense. My intention is for an object of type TStringStringHash
to have at least one indexed property:
const foo: TStringStringHash = { foo: "bar" }
After researching, I have not found a solution that directly addresses this specific issue. Most answers focus on how to assign non-indexed optional properties, but don't cover what I am looking for.
I apologize if the solution to this problem is simple, but as of now, I haven't been able to find a resolution on my own.
Thank you in advance!