Better error message when a module declaration is not found, but a module augmentation is?
#55,347 opened on 2023幎8æ13æ¥
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
declaration, augmentation
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about module augmentation and declaration files
⯠Playground Link
Can't be shown on Playground, since it requires two files
ð» Code
// declaration.d.ts
import { ComponentType } from "react";
declare module "a/b" {
const B: ComponentType<any>;
// const B: import("react").ComponentType<any>;
export default B;
}
// file.ts
import B from "a/b";
ð Actual behavior
The error message is "Cannot find module 'a/b' or its corresponding type declarations (2307)". I know this works as indended from https://github.com/microsoft/TypeScript/issues/49043#issuecomment-1124047244, so my proposal is only about changing the error message.
ð Expected behavior
In the case where TypeScript can't find a declaration of a module but can find its augmentation, it seems very likely the user intended to make it a declaration, but didn't know top-level import/export change the meaning (like I didn't yesterday). It would be nice to have the message tell the user about the problem and guide to fixing it.