microsoft / microsoft/TypeScript

Weak callback parameters length check in js

Open
#42,107 2 comments 2 reactions 1 assignee View on GitHub

@sandersn is already working on this.

Since Dec 28, 2020.

Experimentation Needed Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 4.2.0-dev.20201222

Search Terms: callback parameters length

Code

in .ts everything is ok:

type Test = (a: number, b: number) => number

const a = (func: Test) => func

// OK
const b = a((d, e) => d + e)

// OK: Argument of type '(d: any, e: any, f: any) => any' is not assignable to parameter of type 'Test'
const c = a((d, e, f) => d + e + f)

in .js there's no error if parameters length is wrong:

/** @typedef {(a: number, b: number) => number} Test */

/** @type {(func: Test) => Test} */
const a = func => func

// OK
const b = a((d, e) => d + e)

// Actually: Parameter 'd' implicitly has an 'any' type.
// Expected: Argument of type '(d: any, e: any, f: any) => any' is not assignable to parameter of type 'Test'.
const c = a((d, e, f) => d + e + f)

Expected behavior:
Type checker to show the same error in .js file as in .ts file

Actual behavior:
No errors in .js file

Related Issues:
https://github.com/microsoft/TypeScript/issues/40205

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.