I have a JSON like this. I need an add a type of this JSON. As you can see this is a hash-map structure let's see how we declare the hash-map interface in typescript.
I declared this hash-map in my useState like that.
const [faqCategories, setFaqCategories] = useState<FAQ[]>([]);
We are declaring hash-map like that in typescript.
export interface FAQ { [key: string]: Category[]; }
The whole type system like this for this JSON.
export interface Question { question: string; answer: string; } export interface Category { categoryName: string; iconName: string; questions: Question[]; } export interface FAQ { [key: string]: Category[]; }
Top comments (0)