I'm trying to override the a function signature defined in a TypeScript definition file, however I can't quite get it working. Below is the code that I have, but Typescript seems to be ignoring the augmentation, and is erroring saying that the function expects 2 arguments, but has been given 3.
If I remove the function definition inside the definition file it does set it correctly, so I'm wondering if there is an issue with specifically overriding an existing definition.
The code:
// package/index.d.ts
export interface RealtimeValueGetter {
/**
* Gets the string value of the value, given the payload body
* @param {Context} ctx The project context.
* @param {TPayload} payload This instance of the value's payload data.
*/
getValue: (ctx: Context, payload: unknown) => Promise<string>;
}
export interface EditableRealtimeValue extends RealtimeValueGetter {
/**
* Details how Beak and user's should interact with the value editor for your realtime value.
*/
editor: Editor<TPayload, TEditorState>;
}
// project/augmentations.d.ts
import type { Context, RealtimeValueGetter as OriginalRealtimeValueGetter } from '@getbeak/types/values';
declare module '@getbeak/types-realtime-value' {
interface RealtimeValueGetter extends Omit<OriginalRealtimeValueGetter, 'getValue'> {
/**
* Gets the string value of the value, given the payload body
* @param {Context} ctx The project context.
* @param {TPayload} payload This instance of the value's payload data.
* @param {number} recursiveDepth Used for recursive checks.
*/
getValue: (ctx: Context, payload: unknown, recursiveDepth: number) => Promise<string>;
}
}
// project/index.ts
export async function rtvGetValue(ctx: Context, payload: unknown) {
// Some code removed as unneeded
// Expected 2 arguments, but got 3. ts(2554)
return await extension.getValue(context, payload, recursiveDepth);
}
VSCode showing that TypeScript is detecting the second definition: