My typescript interface defines the structure of my database data as follows:
interface Foo {
bar: {
fish: {
_id: string,
name: string,
}[],
},
starwars: string[],
}
I want to be able to reference specific parts of this interface. For example, I want to pass the data under the key fish
as parameters.
To achieve this, I initially created a new interface for Fish
:
interface Fish {
_id: string,
name: string,
}
interface Foo {
bar: {
fish: Fish[],
},
starwars: string[],
}
function killTheFish(fish: Fish) { ... }
However, I am looking for a more concise way to accomplish this task. Is there a method to reference a specific part of an interface like in the following example?
type Fish = Foo.bar.fish;
If you have any insights on how to reference a part of an interface, please share!