I have a TypeScript object that contains both a known static key and an unknown number of dynamic keys. At a given point in time the object can look like this:
{
created: 32323232,
'https://gbhgr.com/bhtgttg/bffgth': <Observable1>,
'https://trhhhtgrhgr.com/bgbtebg/byrf': <Observable2>,
'https://domain4.com/ngfbgb/frogf': <Observable4>
}
I can't figure out how to type this. The type I came up with:
type Cache = {
created: number,
[key:string]?: Observable<HttpResponse<any>>
}
gives Typescript errors on the line
[key:string]?: Observable<HttpResponse<any>>
on ? (there can be 0,n number of keys so it's optional, therefore the ?):
';' expected.ts(1005)
Property or signature expected.ts(1131)
on Observable:
(method) Observable<HttpResponse>(): any
'Observable', which lacks return-type annotation, implicitly has an 'any' return type.ts(7010)
on HttpResponse:
(type parameter) HttpResponse in Observable<HttpResponse>(): any
'HttpResponse' is declared but its value is never read.ts(6133)
'Observable', which lacks return-type annotation, implicitly has an 'any' return type.ts(7010)
on any:
(type parameter) any in <any>(): any
'any' is declared but its value is never read.ts(6133)
Call signature, which lacks return-type annotation, implicitly has an 'any' return type.ts(7020)
Type parameter name cannot be 'any'.ts(2368)
What do the errors mean? How can I do this?
typescript version: "~4.3.2"