Skip to content

checkJs should be as strict as TS about matching function arity #31888

Closed
@golopot

Description

@golopot

TypeScript Version: 3.6.0-dev.20190613

Search Terms:
overload
higher order function
checkjs

Code

// id.d.ts
declare type Unary = (a: number) => void;
declare type Binary = (a: number, b: number) => void;
export declare function id(fn: Unary): Unary;
export declare function id(fn: Binary): Binary;
export {};
// id.js
export const id = fn => fn;
// index.js
import {id} from './id'

// expected f: Binary
// actual   f: Unary
const f = id((a, b) => {});

// Error: Expected 1 arguments, but got 2.
f(1, 2);
// tsconfig.json
{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "outDir": "dist",
    "noEmit": true,
    "strict": false,
    "esModuleInterop": true
  }
}

Expected behavior:
f is a binary function.
Actual behavior:
f is a unary function.
Playground Link:
N/A
Related Issues:
This issue makes util.promisify in @types/node unusable with checkjs. See
DefinitelyTyped/DefinitelyTyped#33340

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptExperimentation NeededSomeone needs to try this out to see what happensSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions