Skip to content

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

Merged
merged 4 commits into from
Mar 4, 2022

Conversation

liewrichmond
Copy link
Contributor

Fixes #35735

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Oct 7, 2020
@ghost
Copy link

ghost commented Oct 7, 2020

CLA assistant check
All CLA requirements met.

@@ -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; }'.
Copy link
Member

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.

@@ -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)) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)

@weswigham weswigham merged commit ae62da9 into microsoft:main Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Avoid listing missing properties on types with only call/construct signatures
4 participants