Comments (4)
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.
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.
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.
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)
- `tsc` compile `proposal-explicit-resource-management` different from `babel` and `swc` HOT 1
- After enabling noUncheckedIndexedAccess, using ++ on a default undefined does not trigger an error message. HOT 3
- C++-style `const` modifier on class members HOT 2
- Package Import is not working from neither way "CommonJS" or "Module" HOT 4
- Type guard for child not transitive parent object HOT 3
- Error when compiled JavaScript initializes static properties in a class with a hard private method (`#`) that references a static property
- The ?: inference failed; no selection was made between ifTrue and ifFalse. HOT 1
- Add Support for Flow's new component syntax HOT 6
- Documentation: "Creating and Printing a TypeScript AST" example does not work after v4.9.5
- `satisfies` does not work on a variable called `type`
- API: Can't seem to extract JsDoc tags from declaration HOT 2
- Add option to detect and strip internal exports
- false error on generic type alias parameters HOT 5
- Unable to declare an interface that extends `Record<string, nonAnyType>` with additional support functions. HOT 7
- Add support for generic types on a index accessor HOT 2
- `getTextOfJSDocComment` is stripping `#` from JSDoc comment HOT 1
- Enable `allowJs` with `isolatedDeclarations` HOT 1
- JSDoc comment string with the keyword "@private" before import statement in JS file result in cryptic error TS1191 during compilation HOT 2
- `NoInfer` isn't erased and breaks type narrowing HOT 3
- function with overloading incorrectly defines generic variables HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.