Merge pull request #27669 from Microsoft/betterErrorForAccidentalCall
Always emit diagnostic when a call expression can be fixed by adding a semicolon
This commit is contained in:
commit
830be0651c
8 changed files with 86 additions and 85 deletions
|
@ -20101,7 +20101,7 @@ namespace ts {
|
|||
}
|
||||
else {
|
||||
let relatedInformation: DiagnosticRelatedInformation | undefined;
|
||||
if (node.arguments.length === 1 && isTypeAssertion(first(node.arguments))) {
|
||||
if (node.arguments.length === 1) {
|
||||
const text = getSourceFileOfNode(node).text;
|
||||
if (isLineBreak(text.charCodeAt(skipTrivia(text, node.expression.end, /* stopAfterLineBreak */ true) - 1))) {
|
||||
relatedInformation = createDiagnosticForNode(node.expression, Diagnostics.It_is_highly_likely_that_you_are_missing_a_semicolon);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
tests/cases/compiler/betterErrorForAccidentalCall.ts(3,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentalCall.ts(5,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentalCall.ts(7,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentalCall.ts(10,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentalCall.ts(13,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
|
||||
|
||||
==== tests/cases/compiler/betterErrorForAccidentalCall.ts (5 errors) ====
|
||||
declare function foo(): string;
|
||||
|
||||
foo()(1 as number).toString();
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
|
||||
foo() (1 as number).toString();
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
|
||||
foo()
|
||||
~~~~~
|
||||
(1 as number).toString();
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentalCall.ts:7:1: It is highly likely that you are missing a semicolon.
|
||||
|
||||
foo()
|
||||
~~~~~
|
||||
(1 + 2).toString();
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentalCall.ts:10:1: It is highly likely that you are missing a semicolon.
|
||||
|
||||
foo()
|
||||
~~~~~
|
||||
(<number>1).toString();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentalCall.ts:13:1: It is highly likely that you are missing a semicolon.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//// [betterErrorForAccidentallyCallingTypeAssertionExpressions.ts]
|
||||
//// [betterErrorForAccidentalCall.ts]
|
||||
declare function foo(): string;
|
||||
|
||||
foo()(1 as number).toString();
|
||||
|
@ -8,16 +8,16 @@ foo() (1 as number).toString();
|
|||
foo()
|
||||
(1 as number).toString();
|
||||
|
||||
foo()
|
||||
(1 as number).toString();
|
||||
foo()
|
||||
(1 + 2).toString();
|
||||
|
||||
foo()
|
||||
foo()
|
||||
(<number>1).toString();
|
||||
|
||||
|
||||
//// [betterErrorForAccidentallyCallingTypeAssertionExpressions.js]
|
||||
foo()(1).toString();
|
||||
//// [betterErrorForAccidentalCall.js]
|
||||
foo()(1).toString();
|
||||
foo()(1).toString();
|
||||
foo()(1).toString();
|
||||
foo()(1 + 2).toString();
|
||||
foo()(1).toString();
|
|
@ -0,0 +1,25 @@
|
|||
=== tests/cases/compiler/betterErrorForAccidentalCall.ts ===
|
||||
declare function foo(): string;
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))
|
||||
|
||||
foo()(1 as number).toString();
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))
|
||||
|
||||
foo() (1 as number).toString();
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))
|
||||
|
||||
foo()
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))
|
||||
|
||||
(1 as number).toString();
|
||||
|
||||
foo()
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))
|
||||
|
||||
(1 + 2).toString();
|
||||
|
||||
foo()
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentalCall.ts, 0, 0))
|
||||
|
||||
(<number>1).toString();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
=== tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts ===
|
||||
=== tests/cases/compiler/betterErrorForAccidentalCall.ts ===
|
||||
declare function foo(): string;
|
||||
>foo : () => string
|
||||
|
||||
|
@ -34,22 +34,23 @@ foo()
|
|||
>1 : 1
|
||||
>toString : any
|
||||
|
||||
foo()
|
||||
>foo() (1 as number).toString() : any
|
||||
>foo() (1 as number).toString : any
|
||||
>foo() (1 as number) : any
|
||||
foo()
|
||||
>foo() (1 + 2).toString() : any
|
||||
>foo() (1 + 2).toString : any
|
||||
>foo() (1 + 2) : any
|
||||
>foo() : string
|
||||
>foo : () => string
|
||||
|
||||
(1 as number).toString();
|
||||
>1 as number : number
|
||||
(1 + 2).toString();
|
||||
>1 + 2 : number
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>toString : any
|
||||
|
||||
foo()
|
||||
>foo() (<number>1).toString() : any
|
||||
>foo() (<number>1).toString : any
|
||||
>foo() (<number>1) : any
|
||||
foo()
|
||||
>foo() (<number>1).toString() : any
|
||||
>foo() (<number>1).toString : any
|
||||
>foo() (<number>1) : any
|
||||
>foo() : string
|
||||
>foo : () => string
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts(3,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts(5,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts(7,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts(10,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts(13,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
|
||||
|
||||
==== tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts (5 errors) ====
|
||||
declare function foo(): string;
|
||||
|
||||
foo()(1 as number).toString();
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
|
||||
foo() (1 as number).toString();
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
|
||||
foo()
|
||||
~~~~~
|
||||
(1 as number).toString();
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts:7:1: It is highly likely that you are missing a semicolon.
|
||||
|
||||
foo()
|
||||
~~~~~~~~
|
||||
(1 as number).toString();
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts:10:1: It is highly likely that you are missing a semicolon.
|
||||
|
||||
foo()
|
||||
~~~~~~~~
|
||||
(<number>1).toString();
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures.
|
||||
!!! related TS2734 tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts:13:1: It is highly likely that you are missing a semicolon.
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
=== tests/cases/compiler/betterErrorForAccidentallyCallingTypeAssertionExpressions.ts ===
|
||||
declare function foo(): string;
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentallyCallingTypeAssertionExpressions.ts, 0, 0))
|
||||
|
||||
foo()(1 as number).toString();
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentallyCallingTypeAssertionExpressions.ts, 0, 0))
|
||||
|
||||
foo() (1 as number).toString();
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentallyCallingTypeAssertionExpressions.ts, 0, 0))
|
||||
|
||||
foo()
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentallyCallingTypeAssertionExpressions.ts, 0, 0))
|
||||
|
||||
(1 as number).toString();
|
||||
|
||||
foo()
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentallyCallingTypeAssertionExpressions.ts, 0, 0))
|
||||
|
||||
(1 as number).toString();
|
||||
|
||||
foo()
|
||||
>foo : Symbol(foo, Decl(betterErrorForAccidentallyCallingTypeAssertionExpressions.ts, 0, 0))
|
||||
|
||||
(<number>1).toString();
|
||||
|
|
@ -7,8 +7,8 @@ foo() (1 as number).toString();
|
|||
foo()
|
||||
(1 as number).toString();
|
||||
|
||||
foo()
|
||||
(1 as number).toString();
|
||||
foo()
|
||||
(1 + 2).toString();
|
||||
|
||||
foo()
|
||||
foo()
|
||||
(<number>1).toString();
|
Loading…
Reference in a new issue