-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
- Inconsistent 2345
- function generics
- extends 2345
- generics 2345
π Version & Regression Information
- This changed from version 4.7.4+ and above
β― Playground Link
Playground link with relevant code
π» Code
function func<T extends { foo: 1 }>(arg: T): void {}
func({ foo: 1, bar: 1 });
π Actual behavior
bar
property sometimes displayed as valid and sometimes produce an error:
Argument of type '{ foo: 1; bar: number; }' is not assignable to parameter of type '{ foo: 1; }'.
Object literal may only specify known properties, and 'bar' does not exist in type '{ foo: 1; }'.(2345)
When playing with the code live and change bar
to bar222
or ba
sometimes the error shown and sometimes not.
Refreshing the playground link with the changes always remove the error.
Screen.Recording.2022-09-17.at.20.20.57.mov
π Expected behavior
Always display as valid without any error.
{ foo: 1, bar: 1 }
is a valid subtype of { foo: 1 }
and so can legally be used to instantiate T
.
Maybe related to #49490
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue