-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixes #35735: Avoids listing missing properties for types with only call/construct signatures #40973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -120,10 +114,8 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme | |||
!!! error TS2322: Type 'number' is not assignable to type 'string'. | |||
a = (x: string) => 1; | |||
~ | |||
!!! error TS2741: Property 'f' is missing in type '(x: string) => number' but required in type '{ f(x: number): void; }'. | |||
!!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures2.ts:7:10: 'f' is declared here. | |||
!!! error TS2322: Type '(x: string) => number' is not assignable to type '{ f(x: number): void; }'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this one is super subtle! But maybe there's room for a follow-up bug.
src/compiler/checker.ts
Outdated
@@ -18053,7 +18053,7 @@ namespace ts { | |||
const requireOptionalProperties = (relation === subtypeRelation || relation === strictSubtypeRelation) && !isObjectLiteralType(source) && !isEmptyArrayLiteralType(source) && !isTupleType(source); | |||
const unmatchedProperty = getUnmatchedProperty(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false); | |||
if (unmatchedProperty) { | |||
if (reportErrors) { | |||
if (reportErrors && !typeOnlyHasCallOrConstructSignatures(source)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think you only want to do this check when the target doesn't also have a corresponding kind of signature. For example.
declare let x: { (): string; prop: number };
declare let y: { (): string; }
x = y;
y = x;
In the above example, I think you want to show an error for prop
being missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sounds good! I'll look into it. I got busy with something, but I should be able to work on it sometime next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sorry I got sidetracked I'm just revisiting this. Does the code in the PR not raise an error for your example? Using that as a test case gives me
Property 'prop' is missing in type '() => string' but required in type '{ (): string; prop: number; }'.ts(2741)
Fixes #35735