Skip to content

fix: export Volume class directly rather than as a const#1099

Merged
G-Rath merged 1 commit intostreamich:masterfrom
bradzacher:patch-1
May 3, 2025
Merged

fix: export Volume class directly rather than as a const#1099
G-Rath merged 1 commit intostreamich:masterfrom
bradzacher:patch-1

Conversation

@bradzacher
Copy link
Copy Markdown
Contributor

This is a little fix that allows the code to work better with TS.

Currently Volume is re-exported as a const that aliases the class declaration.
This makes it very hard to use the class -- for example the following idiomatic TS code is now invalid:

import { Volume } from 'memfs';

function foo(volume: Volume) { }
//                   ^^^^^^ 'Volume' refers to a value, but is being used as a type here. Did you mean 'typeof Volume'?

// NOTE: the suggestion in the error is wrong and will not allow you to assign an instance
function bar(volume: typeof Volume) { }
bar(new Volume());
//  ^^^^^^^^^^^^ Argument of type 'Volume' is not assignable to parameter of type 'typeof Volume'.
//    Type 'Volume' is missing the following properties from type 'typeof Volume': prototype, fd

If we instead directly export Volume then TS correctly sees the re-exported type as a class declaration and everything works correctly.

Fixes #976

@G-Rath G-Rath changed the title don't re-export Volume as a const from index.ts fix: export Volume class directly rather than as a const May 3, 2025
@G-Rath G-Rath merged commit 9c99798 into streamich:master May 3, 2025
9 of 10 checks passed
github-actions Bot pushed a commit that referenced this pull request May 3, 2025
## [4.17.1](v4.17.0...v4.17.1) (2025-05-03)

### Bug Fixes

* export `Volume` class directly rather than as a `const` ([#1099](#1099)) ([9c99798](9c99798))
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2025

🎉 This PR is included in version 4.17.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggestion] Expose Volume as a class instead of a const

2 participants