'TypeScript only complains module not found for css modules while .d.ts file is closed in VSCode

I have an issue very similar to this question, where a "cannot find module" error is thrown when trying to import CSS modules. However, the suggested answer to that question is to create a declaration.d.ts file like the following:

declare module "*.sass" // or .css or .scss, I am using sass 

This works—kind of. For some reason, VSCode shows me the error only when the .d.ts file is not open. If I keep the declaration file open all the time, no error is shown. However, I obviously don't want to keep the file open all the time, and I would like to just get it to work.

Does anyone know a fix to this problem in VSCode? Perhaps a setting or an extension?

Additional information:

  • VSCode version: 1.65.2
  • OS: Mac OS Big Sur


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source