This is a quick demo of some various Typescript-related issues with Unplugin Auto Imports within an Nx Monorepo setup. This is a default, Vue/Vite-based scaffold from npx create-nx-workspace@latest
with all dependencies up-to-date along with a nx g @nx/js:lib mylib --directory libs
.
To demonstrate the Type issues:
- Clone the repo:
git clone [email protected]:K3TH3R/unplugin-auto-imports-typescript-issue.git
- Install deps:
yarn install
- Open up the file
libs/mylib/src/lib/mylib.ts
andlibs/mylib/vite.config.ts
- In it's default state, running
yarn build
will run the Nx build commands using thelibs/mylib/vite.config.ts
file for the build. Everything works and builds fine. - If you uncomment either of the commented out functions, the build will break due to Type related errors.
In the AutoImport()
within libs/mylib/vite.config.ts
, I have three auto-imports from Cesium: Cartesian2
, Cartesian3
, and Color
as well as a "type" import for the first two of these objects. In the case of Cartesian2
, I'm renaming it to TCartesian2
to avoid namespace clashes in the autoimports.
In the case of Cartesian2
, you can see the global import of the function works fine for the mylib()
default build, however the TCartesian2
global type import (mylib2()
) throws the following TypeScript error:
Return type of exported function has or is using private name 'TCartesian2'.ts(4060)
However, if I do this exact same type alias format (mylib3()
) without global autoimports, it works fine.
In the case of a straight global import of both the function and the type, as shown with Cartesian3
, I am seeing two TypeScript errors:
- Return type of exported function has or is using private name 'Cartesian3'.ts(4060)
- 'Cartesian3' cannot be used as a value because it was exported using 'export type'.ts(1362)
And just to be super sure, I have a second version where I do a global import of the Color
function with no auto type import which also fails with the following errors:
- 'Color' refers to a value, but is being used as a type here. Did you mean 'typeof Color'?ts(2749)
- Return type of exported function has or is using private name 'Color'.ts(4060)
However, I do the exact same format with Cartesian4
below it without issue.