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

TS: allow strong typing of directive value #998

Closed
jods4 opened this issue Apr 20, 2020 · 0 comments · Fixed by #1007
Closed

TS: allow strong typing of directive value #998

jods4 opened this issue Apr 20, 2020 · 0 comments · Fixed by #1007
Labels

Comments

@jods4
Copy link
Contributor

jods4 commented Apr 20, 2020

What problem does this feature solve?

Directive<T> is generic in the type of target element.
It would be nice to have a second generic value (can default to any) for the binding.value type.

So that this can be written:

interface Interval {
  from: number;
  to: number;
}

const dir: Directive<Element, Interval> = (el, { value: { from, to } }) => {
  // from, to are number
}

Without this, you have to cast binding.value explicitely inside the function body.

Hopefully this could be used in the future by Vetur to validate proper directive usage in templates.

What does the proposed API look like?

Modify to Directive<TElement = any, TValue = any>

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

Successfully merging a pull request may close this issue.

2 participants