Skip to content

Function types: overload/merging behavior is unclear #39313

Closed
@layershifter

Description

@layershifter

TypeScript Version: 3.9.2

Search Terms: interface, function types

Expected behavior:

  1. Compiler error if overloads are not supported
  2. foo is resolved to number, string, null type

Actual behavior: foo becomes any on a & b

Parameter 'foo' implicitly has an 'any' type.

Related Issues: N/A

Code

interface A {
    (foo: string): string
    (foo: number): number
}

interface B extends A {
    (foo: null): null
}

const a: A = (foo) => foo
const b: B = (foo) => foo

console.log(a, b)
Output
"use strict";
const a = (foo) => foo;
const b = (foo) => foo;
console.log(a, b);
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions