Subscribe on changes!

Template refs fail to compile with typescript

avatar
Nov 16th 2021

Version

3.2.22

Reproduction link

sfc.vuejs.org/

Steps to reproduce

tsconfig

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "moduleResolution": "node",
    "allowJs": true,
    "sourceMap": true,
    "noImplicitAny": false
  },
  "include": ["Assets/**/*.ts", "Assets/**/*.js", "Assets/**/*.vue"],
  "exclude": ["node_modules"]
}

What is expected?

Compiling

What is actually happening?

Throws a compile error for mismatched types

semantic error TS2322: Type 'object | null' is not assignable to type 'HTMLElement | undefined'.
  Type 'null' is not assignable to type 'HTMLElement | undefined'.

If you remove the empty div in the template, it will compile without problems.

avatar
Nov 16th 2021

If you have a compile error, please provide a reproduction that actually demonstrates this.

the SFC playground doesn't work for this type of reproduction, obviously.

avatar
Nov 16th 2021
avatar
Nov 18th 2021

More info: This only happens if I use <script setup>. Using defineComponent with setup() does work.