Closed
Description
Bug Report
π Search Terms
js, overload
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ entries but non apply.
β― Playground Link
JS version playground link with relevant code
TS version playground link with relevant code
π» Code
JS version:
/**
* @template T
* @template U
* @typedef {T & { [K in Exclude<keyof U, keyof T>]?: never }} ButNot
*/
/**
* @template T
*
* @overload
* @param {ButNot<T, Function>} [context]
* @returns {void}
*
* @overload
* @param {(index: number) => any} mapFn
* @param {T} [context]
* @returns {void}
*/
function foo() {}
// v- β ERROR: Parameter 'k' implicitly has an 'any' type. (7006)
foo((k) => [k]);
// No errors β
foo((k) => [k], undefined);
TS version:
type ButNot<T, U> = T & { [K in Exclude<keyof U, keyof T>]?: never };
function foo<T>(context?: ButNot<T, Function>): void;
function foo<T>(mapFn: (index: number) => any, context?: T): void;
function foo() {}
// No errors β
foo((k) => [k]);
ButNot
is as @RyanCavanaugh suggested in #4196 (comment).
π Actual behavior
Parameter 'k' implicitly has an 'any' type.
error in JS version but not TS one.
π Expected behavior
No errors.
PS: This feels like a bug to me but I'm not sure if there's another way to achieve the expected outcome.