Subscribe on changes!

ref sugar type error when nullable type

avatar
Sep 2nd 2021

Version

Vue 3.2.8 TypeScript 4.4.2 vue-tsc 0.3.0

Reproduction link

SFC Playground

Steps to reproduce

Copy to VSCode and enable Volar (or regular TypeScript file)

What is expected?

the error is fixed

What is actually happening?

import { ref } from 'vue';

let msg = $(ref<string | null>(null));
msg = 'hello world';
msg = null;
//  error TS2322: Type 'null' is not assignable to type 'string & { [RefMarker]?: any; }'.
//   Type 'null' is not assignable to type 'string'.

Related issue: https://github.com/vuejs/vue-next/issues/4433#issuecomment-911707254 https://github.com/vuejs/vue-next/issues/4433#issuecomment-905143953