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

types(reactivity): improve typings for shallowRef #1780

Merged
merged 2 commits into from Aug 19, 2020

Conversation

pikax
Copy link
Member

@pikax pikax commented Aug 5, 2020

vuejs/composition-api#453

const STATUS_INITIAL = 'initial'
const STATUS_READY = 'ready'
const STATUS_INVALIDATING = 'invalidating'

type Status = 'initial' | 'ready' | 'invalidating'

const status = shallowRef<Status>(STATUS_INITIAL)

if (status.value === STATUS_READY) {
    status.value = STATUS_INVALIDATING
}

Explanation shallowRef<Status> is returning Ref<'initial'> | Ref<'ready'> | Ref<'invalidating'> so when you do

if (status.value === STATUS_READY) {
  // status === Ref<'ready'> 
}

@yyx990803 yyx990803 merged commit c86e7ad into vuejs:master Aug 19, 2020
@pikax pikax deleted the types/shallowRef_type_inferrence branch August 15, 2021 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants