Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(fromEvent): fix type error of element reference #4728

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

Merged
merged 6 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(fromEvent): fix ts error: `Type 'null' is not assignable to type …
…'HTMLElement'`
  • Loading branch information
ywenhao committed Apr 25, 2025
commit 3bad4803d5cdbd89912abfb8f649bdadc8486b4b
4 changes: 3 additions & 1 deletion 4 packages/rxjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import { concatAll, map, mergeMap, pluck, scan, take } from 'rxjs/operators'
import { ref } from 'vue'

const BASE_URL = 'https://jsonplaceholder.typicode.com'
const button = ref<HTMLButtonElement>(null)
const button = ref<HTMLButtonElement | null>(null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

// or use `useTemplateRef` in vue3.5+
// const button = useTemplateRef('buttonRef')

const posts = useObservable(
fromEvent(button, 'click').pipe(
Expand Down
3 changes: 1 addition & 2 deletions 3 packages/rxjs/from/_demo.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import type { Ref } from 'vue'
import { interval } from 'rxjs'
import {
map,
Expand All @@ -19,7 +18,7 @@ useSubscription(
interval(1000)
.pipe(
mapTo(1),
takeUntil(fromEvent(button as Ref<HTMLButtonElement>, 'click')),
takeUntil(fromEvent(button, 'click')),
withLatestFrom(from(count, {
immediate: true,
deep: false,
Expand Down
4 changes: 2 additions & 2 deletions 4 packages/rxjs/from/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function from<T>(value: ObservableInput<T> | Ref<T>, watchOptions?: Watch
return fromRxjs(value)
}

export function fromEvent<T extends HTMLElement>(value: MaybeRef<T>, event: string): Observable<Event> {
export function fromEvent<T extends HTMLElement | null>(value: MaybeRef<T>, event: string): Observable<Event> {
if (isRef<T>(value)) {
return new Observable((subscriber) => {
let innerSub: Subscription | undefined
Expand All @@ -23,5 +23,5 @@ export function fromEvent<T extends HTMLElement>(value: MaybeRef<T>, event: stri
}, { immediate: true })
})
}
return fromEventRx(value, event)
return fromEventRx(value as NonNullable<T>, event)
}
3 changes: 1 addition & 2 deletions 3 packages/rxjs/toObserver/_demo.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import type { Ref } from 'vue'
import { interval } from 'rxjs'
import {
map,
Expand All @@ -20,7 +19,7 @@ useSubscription(
interval(1000)
.pipe(
mapTo(1),
takeUntil(fromEvent(button as Ref<HTMLButtonElement>, 'click')),
takeUntil(fromEvent(button, 'click')),
withLatestFrom(from(count).pipe(startWith(0))),
map(([total, curr]) => curr + total),
)
Expand Down
2 changes: 2 additions & 0 deletions 2 packages/rxjs/toObserver/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { shallowRef } from 'vue'

const count = shallowRef(0)
const button = shallowRef<HTMLButtonElement | null>(null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just change it to useTemplateRef.

// or use `useTemplateRef` in vue3.5+
// const button = useTemplateRef('buttonRef')

useSubscription(
interval(1000)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.