- pnpm monorepos setup
- packages are in
packages/
- packages are setup with
"composite": true
intsconfig.json
- packages are in
@my/app
package (inpackages/app
) references@my/lib
(inpackages/lib
)- As a workspace dependency in
package.json
; and - A project reference in
packages/app/tsconfig.json
- As a workspace dependency in
@my/lib
has a path alias set up inpackages/lib/tsconfig.json
which points~/*
tosrc/*
(via thebaseUrl
)@my/lib
has two classesFoo
andBar
Bar
extendsFoo
- The
import
statement inbar.ts
uses the~
path alias to avoid..
in../../other/subpath/foo.ts
- in
@my/app
we usevite-tsconfig-paths
to allowvite
to understand path aliases fromtsconfig.json
- Use Volar in Take Over mode
- Navigate VS Code to
packages/app/src/main.ts
- Mouseover on
@my/lib
on line 5. Volar complains:Output file 'blah/volar-path-alias/packages/lib/src/index.d.ts' has not been built from source file 'blah/volar-path-alias/packages/lib/src/index.ts'.ts(6305)
- Try setting
noProjectReferences
totrue
involar-path-alias.code-workspace
and reload the window - The error has gone away and
foo
is now correctly typed on mouseover asFoo
, butbar
is typed asany
- I think the reason why
Foo
is correctly typed is because it doesn't use the~
path alias in its import/export chain, whilstBar
is incorrectly typed because it does use the~
path alias.
- I think the reason why
- Turn off Take Over mode by enabling the builtin Typescript language features and reload the window
- Note that
foo
andbar
are correctly typed when you mouseover them now, implying that the builtin Typescript is correctly understanding the project reference and path alias
Original README from pnpm create vite
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 <script setup>
SFCs, check out the script setup docs to learn more.
- VS Code + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).
TypeScript cannot handle type information for .vue
imports by default, so we replace the tsc
CLI with vue-tsc
for type checking. In editors, we need TypeScript Vue Plugin (Volar) to make the TypeScript language service aware of .vue
types.
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a Take Over Mode that is more performant. You can enable it by the following steps:
- Disable the built-in TypeScript Extension
- Run
Extensions: Show Built-in Extensions
from VSCode's command palette - Find
TypeScript and JavaScript Language Features
, right click and selectDisable (Workspace)
- Run
- Reload the VSCode window by running
Developer: Reload Window
from the command palette.