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

feat(types): make ImportMetaEnv strictly available #19077

Merged

Conversation

yunics-highfield
Copy link
Contributor

Description

Even if you want to make the type of ImportMetaEnv strict, you can't because [key: string]: any is specified. However, users should be able to choose whether to make the type strict or not.

/** vite-env.d.ts */

/// <reference types="vite/client" />

interface ImportMetaEnv {
  [key: string]: any // If you want to handle ImportMetaEnv ambiguously, add this by yourself.
  readonly MY_ENV: string;
{

@yunics-highfield yunics-highfield changed the title Remove a key definition of ImportMetaEnv feat!: Remove a key definition of ImportMetaEnv Dec 26, 2024
@yunics-highfield yunics-highfield changed the title feat!: Remove a key definition of ImportMetaEnv feat!: ImportMetaEnv Type Improvement Dec 26, 2024
@yunics-highfield yunics-highfield changed the title feat!: ImportMetaEnv Type Improvement feat: ImportMetaEnv Type Improvement Dec 26, 2024
@yunics-highfield yunics-highfield changed the title feat: ImportMetaEnv Type Improvement feat!: Remove a key definition of ImportMetaEnv Dec 26, 2024
@yunics-highfield yunics-highfield changed the title feat!: Remove a key definition of ImportMetaEnv feat!: remove a key definition of ImportMetaEnv Dec 26, 2024
@yunics-highfield yunics-highfield changed the title feat!: remove a key definition of ImportMetaEnv feat: remove a key definition of ImportMetaEnv Dec 26, 2024
@yunics-highfield
Copy link
Contributor Author

I'll handle the lint error later.

@sapphi-red sapphi-red added the p2-to-be-discussed Enhancement under consideration (priority) label Dec 27, 2024
@sapphi-red
Copy link
Member

Would you add a document about this here?
https://vite.dev/guide/env-and-mode.html#intellisense-for-typescript

@yunics-highfield
Copy link
Contributor Author

What do you think of this change?

@yunics-highfield yunics-highfield changed the title feat: remove a key definition of ImportMetaEnv feat: make ImportMetaEnv strictly available Jan 5, 2025
sapphi-red
sapphi-red previously approved these changes Jan 7, 2025
bluwy
bluwy previously approved these changes Jan 7, 2025
@yunics-highfield yunics-highfield dismissed stale reviews from bluwy and sapphi-red via d184511 January 7, 2025 07:56
bluwy
bluwy previously approved these changes Jan 7, 2025
sapphi-red
sapphi-red previously approved these changes Jan 7, 2025
@sapphi-red sapphi-red added this to the 6.3 milestone Mar 19, 2025
@sapphi-red sapphi-red dismissed stale reviews from bluwy and themself via f0a3754 March 19, 2025 10:02
@sapphi-red
Copy link
Member

In the last meeting, we decided to go with an interface instead of a simple type ViteStrictImportMetaEnv so that we can add options later on if needed. I pushed a commit for that.

@sapphi-red
Copy link
Member

/ecosystem-ci run

Copy link

pkg-pr-new bot commented Mar 25, 2025

Open in Stackblitz

npm i https://pkg.pr.new/vite@19077

commit: f0a3754

@vite-ecosystem-ci

This comment was marked as duplicate.

@sapphi-red
Copy link
Member

This PR only changes the types, so the failure of histoire is probably unrelated.

@sapphi-red sapphi-red changed the title feat: make ImportMetaEnv strictly available feat(types): make ImportMetaEnv strictly available Mar 25, 2025
@sapphi-red sapphi-red merged commit 6cf5141 into vitejs:main Mar 25, 2025
18 checks passed
@yunics-highfield yunics-highfield deleted the feature/strict-import-meta-env branch March 25, 2025 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-to-be-discussed Enhancement under consideration (priority) trigger: preview
Projects
Status: Has plan
Development

Successfully merging this pull request may close these issues.

3 participants