Skip to content

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

Open
@bradzacher

Description

@bradzacher

πŸ”Ž 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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions