-
Notifications
You must be signed in to change notification settings - Fork 190
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
Add Type declaration file #57
Conversation
@regou I don't know if you use TS or not, but feel free to provide feedback. |
also cc @ktsn |
@yyx990803 Yes, but never used with vue components. And we may absorb some templates as |
I've used this plugin with TypeScript, so it's a nice thing that this PR will be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm not familiar with Rx. If my comments are wrong, just let me know 🙂
types/index.d.ts
Outdated
declare module "vue/types/vue" { | ||
interface Vue { | ||
$observables: Observables; | ||
$watchAsObservable(exprOrFn: string | Function, options?: WatchOptions): Observable<any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can improve this type by using type parameter like $watch
.
$watchAsObservable<T>(fn: (this: this) => T, options?: WatchOptions): Observable<T>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, returned Observable has a value that is formed of { newValue: T, oldValue: T }
?
https://github.com/vuejs/vue-rx#watchasobservableexporfn-options
types/index.d.ts
Outdated
interface Vue { | ||
$observables: Observables; | ||
$watchAsObservable(exprOrFn: string | Function, options?: WatchOptions): Observable<any> | ||
$eventToObservable(event: string): Observable<any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the returned type is Observable<{ name: string, msg: any }>
types/index.d.ts
Outdated
observable: Observable<T>, | ||
next: (t: T) => void, | ||
error: (e: any) => void, | ||
complete: () => void): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't error
and complete
be optional?
https://github.com/vuejs/vue-rx#subscribetoobservable-next-error-complete
types/index.d.ts
Outdated
next: (t: T) => void, | ||
error: (e: any) => void, | ||
complete: () => void): void | ||
$fromDOMEvent(selector: string, event: string): Observable<any> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can let the return type be Observable<Event>
since this function listens DOM event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, https://github.com/vuejs/vue-rx/blob/master/src/methods/fromDOMEvent.js#L17 selector only applies to native dom element.
declare module 'vue/types/options' { | ||
interface ComponentOptions<V extends Vue> { | ||
subscriptions?: Observables | ((this: V) => Observables) | ||
domStreams?: string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have observableMethods
in component options 😉
https://github.com/vuejs/vue-rx#createobservablemethodmethodname
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @HerringtonDarkholme and reviewers! |
Is this typing compatible with post 2.5 types after merging vuejs/vue#6391 ? Do we need an upgrade PR for that? |
@yyx990803 Looks like we need to update |
Fix vuejs/vue#6569
Fix #52