I want to define a type which is like response headers, which is like:
type Headers = { [key: string]: string }
but if the key is set-cookie
, its type should be string[]
.
I tried
type Headers = { 'set-cookie'?: string[] } & { [key: string]: string };
but for code:
const headers: H = {
'set-cookie': ['cookie'],
'aaa': '111'
}
it has compilation errors:
TS2322: Type '{ 'set-cookie': string[]; aaa: string; }' is not assignable to type 'Headers'.
Type '{ 'set-cookie': string[]; aaa: string; }' is not assignable to type '{ [key: string]: string; }'.
Property ''set-cookie'' is incompatible with index signature.
Type 'string[]' is not assignable to type 'string'.
Is it possible to define such a typing?