Skip to content

Commit 828c00a

Browse files
committed
Fix issue microsoft#22923
1 parent 9b558f9 commit 828c00a

7 files changed

+54
-1
lines changed

src/compiler/checker.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16406,9 +16406,13 @@ namespace ts {
1640616406
}
1640716407
}
1640816408
const suggestion = getSuggestionForNonexistentProperty(propNode, containingType);
16409+
const promisedType = getPromisedTypeOfPromise(containingType);
1640916410
if (suggestion !== undefined) {
1641016411
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestion);
1641116412
}
16413+
else if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
16414+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_await_the_1, declarationNameToString(propNode), typeToString(containingType));
16415+
}
1641216416
else {
1641316417
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
1641416418
}

src/compiler/diagnosticMessages.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,10 @@
20002000
"category": "Error",
20012001
"code": 2569
20022002
},
2003-
2003+
"Property '{0}' does not exist on type '{1}'. Did you forget to await the '{1}'?": {
2004+
"category": "Error",
2005+
"code": 2570
2006+
},
20042007
"JSX element attributes type '{0}' may not be a union type.": {
20052008
"category": "Error",
20062009
"code": 2600
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
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>'?
2+
3+
4+
==== tests/cases/compiler/missingPropertyOfPromise.ts (1 errors) ====
5+
function f(x: Promise<string>) {
6+
x.toLowerCase();
7+
~~~~~~~~~~~
8+
!!! error TS2570: Property 'toLowerCase' does not exist on type 'Promise<string>'. Did you forget to await the 'Promise<string>'?
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [missingPropertyOfPromise.ts]
2+
function f(x: Promise<string>) {
3+
x.toLowerCase();
4+
}
5+
6+
7+
//// [missingPropertyOfPromise.js]
8+
function f(x) {
9+
x.toLowerCase();
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/missingPropertyOfPromise.ts ===
2+
function f(x: Promise<string>) {
3+
>f : Symbol(f, Decl(missingPropertyOfPromise.ts, 0, 0))
4+
>x : Symbol(x, Decl(missingPropertyOfPromise.ts, 0, 11))
5+
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
6+
7+
x.toLowerCase();
8+
>x : Symbol(x, Decl(missingPropertyOfPromise.ts, 0, 11))
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/missingPropertyOfPromise.ts ===
2+
function f(x: Promise<string>) {
3+
>f : (x: Promise<string>) => void
4+
>x : Promise<string>
5+
>Promise : Promise<T>
6+
7+
x.toLowerCase();
8+
>x.toLowerCase() : any
9+
>x.toLowerCase : any
10+
>x : Promise<string>
11+
>toLowerCase : any
12+
}
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f(x: Promise<string>) {
2+
x.toLowerCase();
3+
}

0 commit comments

Comments
 (0)