microsoft / microsoft/TypeScript

Incorrect docs: type compatibility for functions with overloads

Open Beginner friendly
#30,075 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Search Terms: functions with overloads, type compatibility

In the docs, it says: "When a function has overloads, each overload in the source type must be matched by a compatible signature on the target type." But it should be "When a function has overloads, each overload in the source type target type must be matched by a compatible signature on the target type source type."

Code
The actual behaviour is right:

type t1 = {
    (foo: string): string
    (foo: number): number
}

type t2 = {
    (foo: string): string
}

declare let v1: t1;
declare let v2: t2;
v2 = v1 // OK
v1 = v2 // Error

The type on the right side of = is considered "the source type".

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.

Research direction

Start at the linked TypeScript Handbook page on type compatibility and locate the section describing overload compatibility. Compare the wording with the provided assignment example, then update the source documentation so the source and target types are described consistently. Verify the rendered page and the example's stated behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.