It has been confirmed in @Nicholas Tower's comment that your approach is correct.
There is a suggestion for a small improvement: instead of having three string
s in your type definition, each representing different things, consider creating type
aliases for better clarity:
type Uri = string;
type Language = string;
type Name = string;
interface Food {
id: number;
url: Uri;
commonNames: {
[index: Language]: Name[];
};
}
These aliases do not change the typing but enhance understanding of the attributes.
Additionally, using type
aliases allows for attaching TSDoc comments for documentation purposes:
/**
/ * A globally unique, monotonically increasing identifier for a dictionary entry
**/
type Id = number;
/**
/ * A URI
**/
type Uri = string;
/**
/ * A URI referencing a picture of the food
**/
type PictureUri = Uri;
/**
/ * An ISO 639-1:2002 Alpha-2 Language Code
**/
type Language = string;
/**
/ * The name of the food
**/
type Name = string;
interface Food {
id: Id;
url: PictureUri;
commonNames: {
[index: Language]: Name[];
};
}
This example highlights the benefit of using type
aliases for documentation.