Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support typing the model with a generic type argument on the open method #392

Open
davidlav opened this issue Apr 20, 2020 · 2 comments
Open

Comments

@davidlav
Copy link

I'm submitting a feature request

  • Language: TypeScript

Current behavior:
There is not an easy way to enforce type consistency in the data model passed through the open function and where it is consumed in the dialog view model's activate and canActivate functions.

  • What is the expected behavior?
    Add a generic type parameter to open for typing the model (currently the model is simply of type any). For example:
dialogService.open<Customer>({
  viewModel: Dialog,
  model: {
    // TypeScript compiler would throw an error if this object wasn't of type Customer
    ...
  • What is the motivation / use case for changing the behavior?
    The consuming dialog view model would still need to manually type the model, as one currently would, but at least there would be a little more security on the other end knowing that what's being passed in is actually of type Customer.
export class Dialog implements DialogComponentActivate<Customer> {
  activate(model:Customer) {
    ...
@StrahilKazlachev
Copy link
Contributor

StrahilKazlachev commented Apr 20, 2020

Any suggestions/PRs how those can be coupled are welcomed.

In the case where viewModel is passed as string(moduleId) I doubt, something could be done.
On another note, there are 4 interfaces currently, DialogComponentActivate, ... that can be used on the VM.

There is a similar problem how to propagate the dialog "output" type from the VM through the service.

@m-gallesio
Copy link

Typescript now provides ways to get the types of function parameters: https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype
Given this functionality I assume this request would be possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants