When working in tests, or in environments with file system access, you can switch your virtual system with ts.sys to use the real filesystem with the

@typescript/vfs - npm

submited by
Style Pass
2024-12-23 18:00:05

When working in tests, or in environments with file system access, you can switch your virtual system with ts.sys to use the real filesystem with the virtual environment.

If you are running in an environment where you have access to the node_modules folder, then you can can write some code like this:

This list is the default set of definitions (it's important to note that different options for target or lib will affect what this list looks like) and you are grabbing the library's content from the local dependency of TypeScript.

Keeping on top of this list is quite a lot of work, so this library ships functions for generating a map with with these pre-filled from a version of TypeScript available on disk.

If you don't have access to node_modules, then you can use the TypeScript CDN or unpkg to fetch the lib files. This could be up to about 1.5MB, and you should probably store the values in localStorage so that users only have to grab it once.

This package can be used as a commonjs import, an esmodule and directly via a script tag which edits the global namespace. All of these files are embedded inside the released packages.

Leave a Comment