Skip to content

Fix type checking for global variables such as __DEV__ #5

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

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

skirtles-code
Copy link
Owner

Type checking could fail for globals such as __DEV__.

Specifically, it failed for the unit tests. While it did work for the example code, the tests only import MyPanel.vue and MyPanelSection.vue, neither of which use __DEV__. The component ExampleComponent.vue did use __DEV__, but wasn't imported in the tests.

One way to fix this would have been to change the include in tsconfig.vitest.json to include src/globals.d.ts, in addition to env.d.ts.

But it wasn't clear that two separate files are really needed for this. So the fix in this PR merges the contents of src/globals.d.ts into env.d.ts.

The example code has also been expanded to make greater use of __DEV__, helping to catch any future problems. To try to keep the examples somewhat realistic, the new code uses provide/inject. This has the added benefit of helping to test that those functions behave correctly, which is a common problem when a consuming application inadvertently has two copies of Vue present.

@skirtles-code skirtles-code merged commit 2c564b0 into main Mar 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant