I'm trying to learn typescript and I've hit a road bump when it comes to the interfaces, I have a object that I want to save one token and one route in as follows
const obj = {
token: 'thisismytoken',
'/path/to/somewhere': [{ ... }]
}
The problem I'm having here is: how do I generate the interface for this object?
I've tried:
interface iObject {
token: string;
[key: string]: { ... }[]
}
but this generates the error:
TS2411: Property 'token' of type 'string' is not assignable to string index type '{ ... }'.
same thing happens when I try something like:
interface iRoute {
val1: number;
val2: string;
}
interface iObject extends iRoute {
token: string;
}
When I try something like:
interface iObject {
[key: string]: { ... }[] | string;
}
I get the following error when I try to add data to the route variable:
TS2339: Property 'push' does not exist on type 'string | { ... }[]'.
Property 'push' does not exist on type 'string'.
is there any other way to go about doing this?