Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Invalid quick fix for class that's exported as a variable with isolatedDeclarations #61644

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

Open
bradzacher opened this issue May 2, 2025 · 3 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@bradzacher
Copy link
Contributor

πŸ”Ž Search Terms

isolatedDeclarations, quick fix, class

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?isolatedDeclarations=true#code/JYWwDg9gTgLgBAbzgNQgGwK4gKZwL5wBmUEIcA5DiIQM7kDcAUI9gB6SxwDGEAdjfEIQIcALxxe2AO4p0WbAAoAlEyA

πŸ’» Code

import { Volume } from 'memfs';

export const foo = new Volume();

πŸ™ Actual behavior

The "Add annotation of type Volume" quick fix produces broken code:

import { Volume } from 'memfs';
import { Volume } from 'memfs/lib/volume';

export const foo: Volume = new Volume();

The "Add satisfies and an inline type assertion with Volume" quick fix produces broken code:

import { Volume } from 'memfs';
import { Volume } from 'memfs/lib/volume';

export const foo = (new Volume()) satisfies Volume as Volume;

In both cases the quick fix adds another import which creates a TS error due to the duplicate name. If you remove the added import then there is a different error because Volume in this instance is actually a variable that aliases the class declaration -- so it cannot be used as a type.

πŸ™‚ Expected behavior

The quick fix should produce working code.

Additional information about the issue

This might be a unique edge case due to the horrid types in memfs -- IDK why they re-export the class via a variable -- that's seriously cooked.

@bradzacher bradzacher changed the title Invalid quick fix for class that's exported multiple times from a module with isolatedDeclarations Invalid quick fix for class that's exported as a variable with isolatedDeclarations May 2, 2025
@bradzacher
Copy link
Contributor Author

Submitted a fix upstream streamich/memfs#1099 but regardless the TS quick fix should behave correctly here.

@RyanCavanaugh
Copy link
Member

The quick fix should produce working code.

What's the correct code in this case?

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels May 2, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 2, 2025
@bradzacher
Copy link
Contributor Author

What's the correct code in this case?

I'd say one of these two:

import { Volume } from 'memfs';

export const foo: InstanceType<typeof Volume> = new Volume();

or:

import { Volume } from 'memfs';
import { Volume as $SomeUniqueMarker$Volume } from 'memfs/lib/volume';

export const foo: $SomeUniqueMarker$Volume = new Volume();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants