Coming from a Typescript background, I used to define object interfaces like this:
export interface Locale {
login: {
title: string;
actions: {
submit: string;
forgot: string;
}
}
}
However, in Dart, interfaces are implicit and all classes act as interfaces.
Trying to replicate the TypeScript interface in Dart led me to write quite a bit of code:
class BaseLoginActionsLocale {
final String submit;
final String forgot;
BaseLoginActionsLocale({this.submit, this.forgot});
}
class BaseLoginLocale {
final String title;
final BaseLoginActionsLocale actions;
BaseLoginLocale({this.title, this.actions});
}
class BaseLocale {
final BaseLoginLocale login;
BaseLocale({this.login});
}
...
final BaseLocale enLocale = BaseLocale(
login: BaseLoginLocale(
title: 'Login',
actions: BaseLoginActionsLocale(
submit: 'Login',
forgot: 'Forgot Password?'
)
)
);
However, it feels like there's too much boilerplate involved in this approach.
My question is, is there a more concise way to implement this interface in Dart?