Giter Club home page Giter Club logo

Comments (3)

jcalz avatar jcalz commented on July 20, 2024 1

Overloads are checked more loosely than they "should" be, see #13235 among others. You'll probably always be able to find some inconsistency in exactly what is allowed versus rejected.

from typescript.

cassiano avatar cassiano commented on July 20, 2024

Joe and Andrew, I agree that it's virtually impossible for TS to cover all use cases. However, as TS already detects the error in the case below (Playground):

/* overload #1 */ function f0(fn: () => void): (() => void);
/* overload #2 */ function f0(fn: (p1: string) => void): ((p1: string) => void);
/* overload #3 */ function f0(fn: (p1: string, p2: boolean) => void): ((p1: string, p2: boolean) => void);

function f0(fn: (...args: unknown[]) => void): (...args: unknown[]) => void {
  // ...
}

I don't see why it fails to detect the same situation when generic types are present, like the similar code below, considering that string is (sort of) a "subset" (i.e. contained in) of the generic type P1 and boolean is a "subset" of P2 (Playground):

/* overload #1 */ function f0(fn: () => void): (() => void);
/* overload #2 */ function f0<P1>(fn: (p1: P1) => void): ((p1: P1) => void);
/* overload #3 */ function f0<P1, P2>(fn: (p1: P1, p2: P2) => void): ((p1: P1, p2: P2) => void);

from typescript.

typescript-bot avatar typescript-bot commented on July 20, 2024

This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.