Subscribe on changes!

typeof meta.env.xx is error

avatar
Aug 31st 2022

Vue version

3.2.37

Link to minimal reproduction

https://github.com/boot-vue/bug/tree/main/vue3

Steps to reproduce

git clone git@github.com:boot-vue/bug.git

cd vue3

yarn install 

yarn dev

visit http://127.0.0.1:5173/

What is expected?

value :123 / type : number value :PP / type : string value :true / type : boolean

What is actually happening?

value :123 / type : string value :PP / type : string value :true / type : string

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (16) x64 AMD EPYC 7B13
    Memory: 50.03 GB / 62.80 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  npmPackages:
    vue: ^3.2.37 => 3.2.38

Any additional comments?

vite-env.d.ts

interface ImportMetaEnv {
  readonly VITE_XX: number
  readonly VITE_OO: string
  readonly VITE_XXOO: boolean
}

interface ImportMeta {
  readonly env: ImportMetaEnv
}
avatar
Aug 31st 2022
  1. This is about Vite, not Vue
  2. all env variables from .env files are always strings at runtime. Telling typescript otherwise won't change what happens at runtime.