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 2, 2018
1 parent 9b558f9 commit 828c00a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16406,9 +16406,13 @@ namespace ts {
}
}
const suggestion = getSuggestionForNonexistentProperty(propNode, containingType);
const promisedType = getPromisedTypeOfPromise(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 if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_await_the_1, declarationNameToString(propNode), typeToString(containingType));
}
else {
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
}
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 await the '{1}'?": {
"category": "Error",
"code": 2570
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/missingPropertyOfPromise.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests/cases/compiler/missingPropertyOfPromise.ts(2,7): error TS2570: Property 'toLowerCase' does not exist on type 'Promise<string>'. Did you forget to await the 'Promise<string>'?


==== tests/cases/compiler/missingPropertyOfPromise.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 await the 'Promise<string>'?
}

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


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

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

13 changes: 13 additions & 0 deletions tests/baselines/reference/missingPropertyOfPromise.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/missingPropertyOfPromise.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
}

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

0 comments on commit 828c00a

Please sign in to comment.