Skip to content

Commit 8dcba5f

Browse files
committed
Hide function type missing props if return and target type same.
1 parent ad8c209 commit 8dcba5f

12 files changed

+37
-57
lines changed

src/compiler/checker.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -14074,8 +14074,8 @@ namespace ts {
1407414074
source: Type,
1407514075
target: Type,
1407614076
relation: Map<RelationComparisonResult>,
14077-
headMessage: DiagnosticMessage | undefined,
14078-
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
14077+
_headMessage: DiagnosticMessage | undefined,
14078+
_containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
1407914079
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
1408014080
): boolean {
1408114081
const callSignatures = getSignaturesOfType(source, SignatureKind.Call);
@@ -14085,13 +14085,15 @@ namespace ts {
1408514085
const returnType = getReturnTypeOfSignature(s);
1408614086
return !(returnType.flags & (TypeFlags.Any | TypeFlags.Never)) && checkTypeRelatedTo(returnType, target, relation, /*errorNode*/ undefined);
1408714087
})) {
14088-
const resultObj: { errors?: Diagnostic[] } = errorOutputContainer || {};
14089-
checkTypeAssignableTo(source, target, node, headMessage, containingMessageChain, resultObj);
14090-
const diagnostic = resultObj.errors![resultObj.errors!.length - 1];
14088+
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
14089+
const diagnostic = error(node, Diagnostics.Type_0_is_not_assignable_to_type_1, sourceType, targetType);
1409114090
addRelatedInfo(diagnostic, createDiagnosticForNode(
1409214091
node,
1409314092
signatures === constructSignatures ? Diagnostics.Did_you_mean_to_use_new_with_this_expression : Diagnostics.Did_you_mean_to_call_this_expression
1409414093
));
14094+
if (errorOutputContainer && errorOutputContainer.skipLogging) {
14095+
(errorOutputContainer.errors || (errorOutputContainer.errors = [])).push(diagnostic);
14096+
}
1409514097
return true;
1409614098
}
1409714099
}

tests/baselines/reference/checkJsxChildrenProperty4.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
tests/cases/conformance/jsx/file.tsx(24,28): error TS2551: Property 'NAme' does not exist on type 'IUser'. Did you mean 'Name'?
22
tests/cases/conformance/jsx/file.tsx(36,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
3-
Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
43
tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
5-
Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
64

75

86
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
@@ -51,7 +49,6 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) =
5149
) }
5250
~~~~~~~~~~~~~
5351
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
54-
!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
5552
!!! related TS6212 tests/cases/conformance/jsx/file.tsx:36:15: Did you mean to call this expression?
5653
{ user => (
5754
~~~~~~~~~
@@ -60,7 +57,6 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) =
6057
) }
6158
~~~~~~~~~~~~~
6259
!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement<any>'.
63-
!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement<any>': type, props
6460
!!! related TS6212 tests/cases/conformance/jsx/file.tsx:39:15: Did you mean to call this expression?
6561
</FetchUser>
6662
);

tests/baselines/reference/checkJsxChildrenProperty5.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/jsx/file.tsx(20,10): error TS2741: Property 'children' is missing in type '{ a: number; b: string; }' but required in type 'Prop'.
22
tests/cases/conformance/jsx/file.tsx(25,9): error TS2740: Type 'Element' is missing the following properties from type 'Button': render, setState, forceUpdate, state, and 2 more.
3-
tests/cases/conformance/jsx/file.tsx(29,10): error TS2740: Type 'typeof Button' is missing the following properties from type 'Button': render, setState, forceUpdate, props, and 3 more.
3+
tests/cases/conformance/jsx/file.tsx(29,10): error TS2322: Type 'typeof Button' is not assignable to type 'Button'.
44

55

66
==== tests/cases/conformance/jsx/file.tsx (3 errors) ====
@@ -40,6 +40,6 @@ tests/cases/conformance/jsx/file.tsx(29,10): error TS2740: Type 'typeof Button'
4040
<Comp a={10} b="hi">
4141
{Button}
4242
~~~~~~
43-
!!! error TS2740: Type 'typeof Button' is missing the following properties from type 'Button': render, setState, forceUpdate, props, and 3 more.
43+
!!! error TS2322: Type 'typeof Button' is not assignable to type 'Button'.
4444
!!! related TS6213 tests/cases/conformance/jsx/file.tsx:29:10: Did you mean to use 'new' with this expression?
4545
</Comp>;

tests/baselines/reference/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.errors.txt

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(10,8): error TS2741: Property 'x' is missing in type 'typeof Bar' but required in type 'Bar'.
2-
tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(11,8): error TS2740: Type 'DateConstructor' is missing the following properties from type 'Date': toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 37 more.
3-
tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(17,4): error TS2345: Argument of type '() => number' is not assignable to parameter of type 'number'.
1+
tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(10,8): error TS2322: Type 'typeof Bar' is not assignable to type 'Bar'.
2+
tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(11,8): error TS2322: Type 'DateConstructor' is not assignable to type 'Date'.
3+
tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(17,4): error TS2322: Type '() => number' is not assignable to type 'number'.
44
tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(26,5): error TS2322: Type '() => number' is not assignable to type 'number'.
55

66

@@ -16,12 +16,11 @@ tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(2
1616
foo({
1717
x: Bar,
1818
~~~
19-
!!! error TS2741: Property 'x' is missing in type 'typeof Bar' but required in type 'Bar'.
20-
!!! related TS2728 tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts:2:5: 'x' is declared here.
19+
!!! error TS2322: Type 'typeof Bar' is not assignable to type 'Bar'.
2120
!!! related TS6213 tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts:10:8: Did you mean to use 'new' with this expression?
2221
y: Date
2322
~~~~
24-
!!! error TS2740: Type 'DateConstructor' is missing the following properties from type 'Date': toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 37 more.
23+
!!! error TS2322: Type 'DateConstructor' is not assignable to type 'Date'.
2524
!!! related TS6213 tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts:11:8: Did you mean to use 'new' with this expression?
2625
}, getNum());
2726

@@ -30,7 +29,7 @@ tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts(2
3029
y: new Date()
3130
}, getNum);
3231
~~~~~~
33-
!!! error TS2345: Argument of type '() => number' is not assignable to parameter of type 'number'.
32+
!!! error TS2322: Type '() => number' is not assignable to type 'number'.
3433
!!! related TS6212 tests/cases/compiler/didYouMeanElaborationsForExpressionsWhichCouldBeCalled.ts:17:4: Did you mean to call this expression?
3534

3635

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tests/cases/compiler/elaborationForPossiblyCallableTypeStillReferencesArgumentAtTopLevel.ts(3,4): error TS2345: Argument of type 'new () => number' is not assignable to parameter of type 'number'.
1+
tests/cases/compiler/elaborationForPossiblyCallableTypeStillReferencesArgumentAtTopLevel.ts(3,4): error TS2322: Type 'new () => number' is not assignable to type 'number'.
22

33

44
==== tests/cases/compiler/elaborationForPossiblyCallableTypeStillReferencesArgumentAtTopLevel.ts (1 errors) ====
55
declare var ohno: new () => number;
66
declare function ff(t: number): void;
77
ff(ohno)
88
~~~~
9-
!!! error TS2345: Argument of type 'new () => number' is not assignable to parameter of type 'number'.
9+
!!! error TS2322: Type 'new () => number' is not assignable to type 'number'.
1010
!!! related TS6213 tests/cases/compiler/elaborationForPossiblyCallableTypeStillReferencesArgumentAtTopLevel.ts:3:4: Did you mean to use 'new' with this expression?

tests/baselines/reference/functionSignatureAssignmentCompat1.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
tests/cases/compiler/functionSignatureAssignmentCompat1.ts(10,21): error TS2322: Type '(delimiter?: string) => ParserFunc' is not assignable to type 'ParserFunc'.
2-
Types of parameters 'delimiter' and 'eventEmitter' are incompatible.
3-
Type 'number' is not assignable to type 'string'.
42

53

64
==== tests/cases/compiler/functionSignatureAssignmentCompat1.ts (1 errors) ====
@@ -16,7 +14,5 @@ tests/cases/compiler/functionSignatureAssignmentCompat1.ts(10,21): error TS2322:
1614
var d: ParserFunc = parsers.readline; // not ok
1715
~~~~~~~~~~~~~~~~
1816
!!! error TS2322: Type '(delimiter?: string) => ParserFunc' is not assignable to type 'ParserFunc'.
19-
!!! error TS2322: Types of parameters 'delimiter' and 'eventEmitter' are incompatible.
20-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
2117
!!! related TS6212 tests/cases/compiler/functionSignatureAssignmentCompat1.ts:10:21: Did you mean to call this expression?
2218
var e: ParserFunc = parsers.readline(); // ok

tests/baselines/reference/optionalParamAssignmentCompat.errors.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
tests/cases/compiler/optionalParamAssignmentCompat.ts(10,13): error TS2322: Type '(p1?: string) => I1' is not assignable to type 'I1'.
2-
Types of parameters 'p1' and 'p1' are incompatible.
3-
Type 'number' is not assignable to type 'string'.
42

53

64
==== tests/cases/compiler/optionalParamAssignmentCompat.ts (1 errors) ====
@@ -16,7 +14,5 @@ tests/cases/compiler/optionalParamAssignmentCompat.ts(10,13): error TS2322: Type
1614
var d: I1 = i2.m1; // should error
1715
~~~~~
1816
!!! error TS2322: Type '(p1?: string) => I1' is not assignable to type 'I1'.
19-
!!! error TS2322: Types of parameters 'p1' and 'p1' are incompatible.
20-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
2117
!!! related TS6212 tests/cases/compiler/optionalParamAssignmentCompat.ts:10:13: Did you mean to call this expression?
2218

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(7,5): error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'.
2-
Type '(x: string) => string' is not assignable to type 'string'.
3-
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(8,5): error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'.
4-
Type '(x: string) => string' is not assignable to type 'string'.
1+
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(7,5): error TS2322: Type '() => (x: string) => string' is not assignable to type '(x: string) => string'.
2+
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(8,5): error TS2322: Type '() => (x: string) => string' is not assignable to type '(x: string) => string'.
53

64

75
==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts (2 errors) ====
@@ -13,12 +11,10 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts(8,5):
1311
foo(g);
1412
foo(() => g);
1513
~~~~~~~
16-
!!! error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'.
17-
!!! error TS2345: Type '(x: string) => string' is not assignable to type 'string'.
14+
!!! error TS2322: Type '() => (x: string) => string' is not assignable to type '(x: string) => string'.
1815
!!! related TS6212 tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts:7:5: Did you mean to call this expression?
1916
foo(x);
2017
~
21-
!!! error TS2345: Argument of type '() => (x: string) => string' is not assignable to parameter of type '(x: string) => string'.
22-
!!! error TS2345: Type '(x: string) => string' is not assignable to type 'string'.
18+
!!! error TS2322: Type '() => (x: string) => string' is not assignable to type '(x: string) => string'.
2319
!!! related TS6212 tests/cases/conformance/parser/ecmascript5/RegressionTests/parser536727.ts:8:5: Did you mean to call this expression?
2420

tests/baselines/reference/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.errors.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(12,1): error TS2741: Property 'prop' is missing in type 'C' but required in type 'A'.
2-
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(13,5): error TS2741: Property 'prop' is missing in type 'typeof B' but required in type 'A'.
2+
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(13,5): error TS2322: Type 'typeof B' is not assignable to type 'A'.
33
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(16,5): error TS2741: Property 'prop' is missing in type 'C' but required in type 'B'.
4-
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(17,5): error TS2741: Property 'prop' is missing in type 'typeof B' but required in type 'B'.
4+
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(17,5): error TS2322: Type 'typeof B' is not assignable to type 'B'.
55

66

77
==== tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts (4 errors) ====
@@ -22,8 +22,7 @@ tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.
2222
!!! related TS2728 tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts:2:5: 'prop' is declared here.
2323
a = B; // error prop is missing
2424
~
25-
!!! error TS2741: Property 'prop' is missing in type 'typeof B' but required in type 'A'.
26-
!!! related TS2728 tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts:2:5: 'prop' is declared here.
25+
!!! error TS2322: Type 'typeof B' is not assignable to type 'A'.
2726
!!! related TS6213 tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts:13:5: Did you mean to use 'new' with this expression?
2827
a = C;
2928

@@ -33,8 +32,7 @@ tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.
3332
!!! related TS2728 tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts:5:12: 'prop' is declared here.
3433
b = B; // error prop is missing
3534
~
36-
!!! error TS2741: Property 'prop' is missing in type 'typeof B' but required in type 'B'.
37-
!!! related TS2728 tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts:5:12: 'prop' is declared here.
35+
!!! error TS2322: Type 'typeof B' is not assignable to type 'B'.
3836
!!! related TS6213 tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts:17:5: Did you mean to use 'new' with this expression?
3937
b = C;
4038
b = a;

tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon
44
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(24,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
55
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(31,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'.
66
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(32,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'.
7-
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(37,8): error TS2741: Property 'foo' is missing in type 'typeof A' but required in type 'A'.
8-
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(38,8): error TS2741: Property 'foo' is missing in type 'typeof B' but required in type 'A'.
7+
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(37,8): error TS2322: Type 'typeof A' is not assignable to type 'A'.
8+
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(38,8): error TS2322: Type 'typeof B' is not assignable to type 'A'.
99

1010

1111
==== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts (8 errors) ====
@@ -59,12 +59,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon
5959
var b: { [x: string]: A } = {
6060
a: A,
6161
~
62-
!!! error TS2741: Property 'foo' is missing in type 'typeof A' but required in type 'A'.
63-
!!! related TS2728 tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts:4:5: 'foo' is declared here.
62+
!!! error TS2322: Type 'typeof A' is not assignable to type 'A'.
6463
!!! related TS6213 tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts:37:8: Did you mean to use 'new' with this expression?
6564
b: B
6665
~
67-
!!! error TS2741: Property 'foo' is missing in type 'typeof B' but required in type 'A'.
68-
!!! related TS2728 tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts:4:5: 'foo' is declared here.
66+
!!! error TS2322: Type 'typeof B' is not assignable to type 'A'.
6967
!!! related TS6213 tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts:38:8: Did you mean to use 'new' with this expression?
7068
}

tests/baselines/reference/typeMatch1.errors.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/compiler/typeMatch1.ts(18,1): error TS2322: Type 'D' is not assignable to type 'C'.
22
Types have separate declarations of a private property 'x'.
3-
tests/cases/compiler/typeMatch1.ts(19,4): error TS2741: Property 'x' is missing in type 'typeof C' but required in type 'C'.
3+
tests/cases/compiler/typeMatch1.ts(19,4): error TS2322: Type 'typeof C' is not assignable to type 'C'.
44
tests/cases/compiler/typeMatch1.ts(20,1): error TS2367: This condition will always return 'false' since the types 'typeof C' and 'typeof D' have no overlap.
55

66

@@ -28,8 +28,7 @@ tests/cases/compiler/typeMatch1.ts(20,1): error TS2367: This condition will alwa
2828
!!! error TS2322: Types have separate declarations of a private property 'x'.
2929
x6=C;
3030
~
31-
!!! error TS2741: Property 'x' is missing in type 'typeof C' but required in type 'C'.
32-
!!! related TS2728 tests/cases/compiler/typeMatch1.ts:12:19: 'x' is declared here.
31+
!!! error TS2322: Type 'typeof C' is not assignable to type 'C'.
3332
!!! related TS6213 tests/cases/compiler/typeMatch1.ts:19:4: Did you mean to use 'new' with this expression?
3433
C==D;
3534
~~~~

0 commit comments

Comments
 (0)