Closed
Description
I'm trying to overload an existing arrow function in a module, exported as const
. It works perfectly fine with overrides for function, class and interface, but failing for arrow function declared as const
.
Also tried with:
export interface myVar {
(param: number): number
}
It works, but then the arrow function become unusable because it treats it as interface
and it's not callable.
TypeScript Version: 3.9.2
Search Terms: const, module augmentation, declaration merging, overload, block-scope variable
Expected behavior:
Allow to override block-scoped variables if it's referring to an arrow function. Just like a function
.
Actual behavior:
Cannot redeclare block-scoped variable 'myVar'.(2451)
Related Issues:
- Merging constants with namespaces #18163 (maybe related)
Code
declare module 'test' {
// export function works
export function myFunc(param: string): string;
// export const doesn't work
export const myVar: (param: string) => string;
}
declare module 'test' {
export function myFunc(param: number): number;
export const myVar: (param: number) => number;
}
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"useDefineForClassFields": false,
"alwaysStrict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"downlevelIteration": false,
"noEmitHelpers": false,
"noLib": false,
"noStrictGenericChecks": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"esModuleInterop": true,
"preserveConstEnums": false,
"removeComments": false,
"skipLibCheck": false,
"checkJs": false,
"allowJs": false,
"declaration": true,
"experimentalDecorators": false,
"emitDecoratorMetadata": false,
"target": "ES2017",
"module": "ESNext"
}
}
Playground Link: Provided