Skip to content

Undefined is complained when bind :style to an array #7955

@yuwu9145

Description

@yuwu9145

Vue version

3.2.47

Link to minimal reproduction

https://github.com/yuwu9145/vue-StyleValue-type

Steps to reproduce

  1. clone the repo
  2. run npx vue-tsc --noEmit

What is expected?

No type error

What is actually happening?

src/App.vue:2:17 - error TS2322: Type 'undefined' is not assignable to type 'StyleValue'.

2   <h1 :style="[ style, {background: 'green'} ]">Test</h1>

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 4.67 GB / 7.62 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.19.0/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.0/bin/npm
  npmPackages:
    vue: ^3.2.47 => 3.2.47

Any additional comments?

[undefined, {...other style object}] works perfectly fine in runtime. check link

In addition, undefined can be directly assigned to :style without type error

<h1 :style="undefined">Test</h1> // no type error

Therefore, [undefined] should not be type complained

Metadata

Metadata

Assignees

No one assigned

    Labels

    🍰 p2-nice-to-havePriority 2: this is not breaking anything but nice to have it addressed.scope: types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy