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: improve typings for shallowRef #457

Merged
merged 1 commit into from
Aug 5, 2020

Conversation

pikax
Copy link
Member

@pikax pikax commented Aug 5, 2020

fix #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'> 
}

Same as vuejs/core#1780

@pikax pikax requested a review from antfu August 5, 2020 08:18
@antfu antfu merged commit b4e4655 into vuejs:master Aug 5, 2020
@pikax pikax deleted the types/shallowRef_type_inferrence branch August 10, 2020 15:38
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.

shallowRef invalid TypeScript type inference
2 participants