Skip to content

No implicit any error on call in JS but not in TSΒ #55062

Closed
@ziadkh0

Description

@ziadkh0

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.

Metadata

Metadata

Assignees

Labels

Design LimitationConstraints of the existing architecture prevent this from being fixedNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions