Answer the question
In order to leave comments, you need to log in
Is it possible to describe an object that can have any keys?
I have a type such as "Animal" and any keys can come to this object, but the value of these keys is always String.
For example, for one response, I get the following object:
General: {
name: "test",
example: {
breed: "test",
eyes: "test"
}
}
General: {
name: "test",
example: {
something: "test"
somethingElse: "test"
someOtherField: "test"
}
}
type Animal {
// how i can describe this object?
}
type General {
name: String
example: Animal
}
Answer the question
In order to leave comments, you need to log in
type Animal = {
[key: string]: string;
};
type Animal = {
[<любое имя>: <тип ключей>]: <тип значений>;
};
The name must be a valid identifier, why is it needed TS - I xs, but without it string | number | symbol
, moreover, there are troubles with symbol, there is only a union of specific symbols type Animal = Record<string, string>;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question