Skip to content

Commit

Permalink
Fix issue #22923
Browse files Browse the repository at this point in the history
  • Loading branch information
akhomchenko committed Apr 5, 2018
1 parent 9b558f9 commit 134b341
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16405,12 +16405,18 @@ namespace ts {
}
}
}
const suggestion = getSuggestionForNonexistentProperty(propNode, containingType);
if (suggestion !== undefined) {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestion);
const promisedType = getPromisedTypeOfPromise(containingType);
if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType));
}
else {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
const suggestion = getSuggestionForNonexistentProperty(propNode, containingType);
if (suggestion !== undefined) {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestion);
}
else {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
}
}
diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo));
}
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,10 @@
"category": "Error",
"code": 2569
},

"Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?": {
"category": "Error",
"code": 2570
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests/cases/compiler/nonexistentPropertyAvailableOnPromisedType.ts(2,7): error TS2570: Property 'toLowerCase' does not exist on type 'Promise<string>'. Did you forget to use 'await'?


==== tests/cases/compiler/nonexistentPropertyAvailableOnPromisedType.ts (1 errors) ====
function f(x: Promise<string>) {
x.toLowerCase();
~~~~~~~~~~~
!!! error TS2570: Property 'toLowerCase' does not exist on type 'Promise<string>'. Did you forget to use 'await'?
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [nonexistentPropertyAvailableOnPromisedType.ts]
function f(x: Promise<string>) {
x.toLowerCase();
}


//// [nonexistentPropertyAvailableOnPromisedType.js]
function f(x) {
x.toLowerCase();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/compiler/nonexistentPropertyAvailableOnPromisedType.ts ===
function f(x: Promise<string>) {
>f : Symbol(f, Decl(nonexistentPropertyAvailableOnPromisedType.ts, 0, 0))
>x : Symbol(x, Decl(nonexistentPropertyAvailableOnPromisedType.ts, 0, 11))
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))

x.toLowerCase();
>x : Symbol(x, Decl(nonexistentPropertyAvailableOnPromisedType.ts, 0, 11))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/nonexistentPropertyAvailableOnPromisedType.ts ===
function f(x: Promise<string>) {
>f : (x: Promise<string>) => void
>x : Promise<string>
>Promise : Promise<T>

x.toLowerCase();
>x.toLowerCase() : any
>x.toLowerCase : any
>x : Promise<string>
>toLowerCase : any
}

12 changes: 12 additions & 0 deletions tests/baselines/reference/nonexistentPropertyOnUnion.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests/cases/compiler/nonexistentPropertyOnUnion.ts(2,7): error TS2339: Property 'toLowerCase' does not exist on type 'string | Promise<string>'.
Property 'toLowerCase' does not exist on type 'Promise<string>'.


==== tests/cases/compiler/nonexistentPropertyOnUnion.ts (1 errors) ====
function f(x: string | Promise<string>) {
x.toLowerCase();
~~~~~~~~~~~
!!! error TS2339: Property 'toLowerCase' does not exist on type 'string | Promise<string>'.
!!! error TS2339: Property 'toLowerCase' does not exist on type 'Promise<string>'.
}

10 changes: 10 additions & 0 deletions tests/baselines/reference/nonexistentPropertyOnUnion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [nonexistentPropertyOnUnion.ts]
function f(x: string | Promise<string>) {
x.toLowerCase();
}


//// [nonexistentPropertyOnUnion.js]
function f(x) {
x.toLowerCase();
}
10 changes: 10 additions & 0 deletions tests/baselines/reference/nonexistentPropertyOnUnion.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/compiler/nonexistentPropertyOnUnion.ts ===
function f(x: string | Promise<string>) {
>f : Symbol(f, Decl(nonexistentPropertyOnUnion.ts, 0, 0))
>x : Symbol(x, Decl(nonexistentPropertyOnUnion.ts, 0, 11))
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))

x.toLowerCase();
>x : Symbol(x, Decl(nonexistentPropertyOnUnion.ts, 0, 11))
}

13 changes: 13 additions & 0 deletions tests/baselines/reference/nonexistentPropertyOnUnion.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/nonexistentPropertyOnUnion.ts ===
function f(x: string | Promise<string>) {
>f : (x: string | Promise<string>) => void
>x : string | Promise<string>
>Promise : Promise<T>

x.toLowerCase();
>x.toLowerCase() : any
>x.toLowerCase : any
>x : string | Promise<string>
>toLowerCase : any
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests/cases/compiler/nonexistentPropertyUnavailableOnPromisedType.ts(2,7): error TS2339: Property 'toLowerCase' does not exist on type 'Promise<number>'.


==== tests/cases/compiler/nonexistentPropertyUnavailableOnPromisedType.ts (1 errors) ====
function f(x: Promise<number>) {
x.toLowerCase();
~~~~~~~~~~~
!!! error TS2339: Property 'toLowerCase' does not exist on type 'Promise<number>'.
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [nonexistentPropertyUnavailableOnPromisedType.ts]
function f(x: Promise<number>) {
x.toLowerCase();
}


//// [nonexistentPropertyUnavailableOnPromisedType.js]
function f(x) {
x.toLowerCase();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/compiler/nonexistentPropertyUnavailableOnPromisedType.ts ===
function f(x: Promise<number>) {
>f : Symbol(f, Decl(nonexistentPropertyUnavailableOnPromisedType.ts, 0, 0))
>x : Symbol(x, Decl(nonexistentPropertyUnavailableOnPromisedType.ts, 0, 11))
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))

x.toLowerCase();
>x : Symbol(x, Decl(nonexistentPropertyUnavailableOnPromisedType.ts, 0, 11))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/nonexistentPropertyUnavailableOnPromisedType.ts ===
function f(x: Promise<number>) {
>f : (x: Promise<number>) => void
>x : Promise<number>
>Promise : Promise<T>

x.toLowerCase();
>x.toLowerCase() : any
>x.toLowerCase : any
>x : Promise<number>
>toLowerCase : any
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function f(x: Promise<string>) {
x.toLowerCase();
}
3 changes: 3 additions & 0 deletions tests/cases/compiler/nonexistentPropertyOnUnion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function f(x: string | Promise<string>) {
x.toLowerCase();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function f(x: Promise<number>) {
x.toLowerCase();
}

0 comments on commit 134b341

Please sign in to comment.