I am encountering challenges with implementing declaration merging on an interface from a library that I created.
An example illustrating the issue using StackBlitz can be viewed here: https://stackblitz.com/edit/typescript-qxvrte (issues persist in both StackBlitz and my local development setup).
My current configuration is as follows:
// file_a.ts
declare module '@rschedule/core' {
interface DateAdapterType {
one: string;
}
}
// file_b.ts
import { DateAdapterType } from '@rschedule/core';
import './file_a';
function test(date: DateAdapterType) {
date.base; // expecting type `DateAdapterBase`
date.one; // expecting type `string`
}
The issue I am facing is that my local type declaration in file_a
seems to overwrite the type of DateAdapterType
instead of merging with it. As a result, in the given example, date
has the structure { one: string }
when it should have been
{ base: DateAdapterBase; one: string }
.
Is there something I am missing about how declaration merging functions?
You can access the source code for @rschedule/core
here. The distributed npm code can be viewed here.
Any assistance would be highly appreciated!
PS
I have observed that updating @rschedule/core
to declare DateAdapterType
as a global type (i.e.
declare global { interface DateAdapterType ... }
) resolves the issue with declaration merging.