在使用 TypeScript 時,有沒有辦法將模組增強擴展到套件範圍?
我有一個來自外部庫的模組,我在應用程式代碼中對其進行增強:
// in
type MyType = {
a: string;
b: string;
};
declare module "@some/library" {
interface LibraryType extends MyType{}
}
這在一個模組中運作得非常好,但我想將這個宣告分享給我套件中的所有模組。如果我將這個 declare 聲明移到一個 .d.ts 文件中:
import {
MyType,
} from "elsewhere";
declare global {
declare module "@some/library" {
interface LibraryType extends MyType{}
}
}
然後它停止工作(我不再看到 a 和 b 在 LibraryType 上)。我哪裡做錯了?