Skip to content
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

Declaration merging is detected only if the file is open is VSCode #561

Closed
yooneskh opened this issue Oct 12, 2021 · 5 comments · Fixed by denoland/deno#17979
Closed

Declaration merging is detected only if the file is open is VSCode #561

yooneskh opened this issue Oct 12, 2021 · 5 comments · Fixed by denoland/deno#17979

Comments

@yooneskh
Copy link

Explain the bug
Declaration merging is detected by the VSCode only if the file that specifies the additional interface options is fully open. as soon as the file closes, VSCode gives out errors.

To Reproduce
These are the files needed

// a.ts
export interface IUser {
  name: string;
}

// b.ts
import './a.ts'; // this import is needed and is also needed in tsc itself

declare module './a.ts' {
  interface IUser {
    phoneNumber: string;
  }
}

// c.ts
import { IUser } from './a.ts';

const user: IUser = {
  name: '---',
  phoneNumber: '---'
};
  1. Create the above files
  2. Open them all in the vs code
  3. Everything is ok
  4. Close the b.ts file and as soon as you make a change in c.ts file (to trigger linting i guess) an error is given which indicates phoneNumber is invalid.
  5. Open the b.ts file again and make a change in c.ts file and everything is ok

Expected behavior
A file being open or close should not change the linting behavior. Also note that the deno itself is ok with this and correctly handles declaration merging.

Versions
vscode: 1.61.0 deno: 1.14.3 extension: 3.9.1

@yooneskh yooneskh changed the title Declaration working is detected only if the file is open is VSCode Declaration merging is detected only if the file is open is VSCode Oct 17, 2021
@yooneskh
Copy link
Author

yooneskh commented Dec 7, 2022

Is this still being worked on? Is there a workaround for this?

@bartlomieju
Copy link
Member

@dsherret could you recent refactor to the LSP fix this problem?

@dsherret
Copy link
Member

dsherret commented Dec 7, 2022

No. If the file is closed and isn't discoverable by the module graph from any files then it won't be found. The way to make it work is to ensure the declaration merging occurs is to import User from a place that imports a.ts and does declaration merging there, or even better to not use declaration merging and instead extend the type with a new type then use that (which I know is not always possible).

@yooneskh
Copy link
Author

yooneskh commented Dec 7, 2022

Thank you for your quick response @dsherret @bartlomieju

Is this planned to be fixed in the future?

@yooneskh
Copy link
Author

One workaround for this is to have a file (i name it declarations.helper.ts) and do a simple import to all of your files that have declaration merging inside them, then have this file open all the time (preferably pin it in vscode).

// declarations.helper.ts
import '../a.ts'; // have declaration merging inside them (declare module)
import '../b.ts';
import '../c.ts';

This helps a lot if you have some amount of files that does this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants