Giter Site home page Giter Site logo

Comments (4)

RyanCavanaugh avatar RyanCavanaugh commented on April 27, 2024 2

I don't think there's any way to come up with a consistent set of rules when there's an object that doesn't satisfy the constraint. Once there's a contradiction in the system, nothing's going to "make sense".

from typescript.

Andarist avatar Andarist commented on April 27, 2024 1

Admittedly, this is a little bit confusing. In the second example, it fails to infer Config since that empty barConfig: {} doesn't satisfy your constraint (Configuration<Targ>). So in this case, it errors on those excess properties as the target type is just Configuration<Targ>. On the other hand, in the first example, it manages to infer it successfully and it can't error there. The point of inference is to infer types more specific than the constraint and that's true about what it inferred there.

from typescript.

fatcerberus avatar fatcerberus commented on April 27, 2024

Your playground link is broken, just to let you know.

Keep in mind, for future reference, that the excess property check is more of a built-in lint rule than a type check, so in general there's no guarantee that it will be consistently applied; the type rules themselves do allow excess properties, even in non-generic contexts.

Honestly I don't actually know what the expected behaviour here is. I feel, given my understanding of 'extends' that it's likely the right behaviour to not have any error on 'c' in both cases.

I'd be inclined to agree; T extends U is an explicit signal that you accept subtypes of U. It's probably a bug that EPC kicks in here at all.
edit: Andarist explained it above. EPC is done against Configuration<Targ> because generic inference from the object literal itself failed.

from typescript.

typescript-bot avatar typescript-bot commented on April 27, 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.