Skip to content

Commit 457fb64

Browse files
committed
Fix issue microsoft#22923
1 parent 9b558f9 commit 457fb64

12 files changed

+103
-2
lines changed

src/compiler/checker.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -16410,7 +16410,13 @@ namespace ts {
1641016410
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestion);
1641116411
}
1641216412
else {
16413-
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
16413+
const promisedType = getPromisedTypeOfPromise(containingType);
16414+
if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
16415+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_await_the_1, declarationNameToString(propNode), typeToString(containingType));
16416+
}
16417+
else {
16418+
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
16419+
}
1641416420
}
1641516421
diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo));
1641616422
}

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/nonexistentPropertyAvailableOnPromisedType.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/nonexistentPropertyAvailableOnPromisedType.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+
//// [nonexistentPropertyAvailableOnPromisedType.ts]
2+
function f(x: Promise<string>) {
3+
x.toLowerCase();
4+
}
5+
6+
7+
//// [nonexistentPropertyAvailableOnPromisedType.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/nonexistentPropertyAvailableOnPromisedType.ts ===
2+
function f(x: Promise<string>) {
3+
>f : Symbol(f, Decl(nonexistentPropertyAvailableOnPromisedType.ts, 0, 0))
4+
>x : Symbol(x, Decl(nonexistentPropertyAvailableOnPromisedType.ts, 0, 11))
5+
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
6+
7+
x.toLowerCase();
8+
>x : Symbol(x, Decl(nonexistentPropertyAvailableOnPromisedType.ts, 0, 11))
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/nonexistentPropertyAvailableOnPromisedType.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,10 @@
1+
tests/cases/compiler/nonexistentPropertyUnavailableOnPromisedType.ts(2,7): error TS2339: Property 'toLowerCase' does not exist on type 'Promise<number>'.
2+
3+
4+
==== tests/cases/compiler/nonexistentPropertyUnavailableOnPromisedType.ts (1 errors) ====
5+
function f(x: Promise<number>) {
6+
x.toLowerCase();
7+
~~~~~~~~~~~
8+
!!! error TS2339: Property 'toLowerCase' does not exist on type 'Promise<number>'.
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [nonexistentPropertyUnavailableOnPromisedType.ts]
2+
function f(x: Promise<number>) {
3+
x.toLowerCase();
4+
}
5+
6+
7+
//// [nonexistentPropertyUnavailableOnPromisedType.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/nonexistentPropertyUnavailableOnPromisedType.ts ===
2+
function f(x: Promise<number>) {
3+
>f : Symbol(f, Decl(nonexistentPropertyUnavailableOnPromisedType.ts, 0, 0))
4+
>x : Symbol(x, Decl(nonexistentPropertyUnavailableOnPromisedType.ts, 0, 11))
5+
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
6+
7+
x.toLowerCase();
8+
>x : Symbol(x, Decl(nonexistentPropertyUnavailableOnPromisedType.ts, 0, 11))
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/nonexistentPropertyUnavailableOnPromisedType.ts ===
2+
function f(x: Promise<number>) {
3+
>f : (x: Promise<number>) => void
4+
>x : Promise<number>
5+
>Promise : Promise<T>
6+
7+
x.toLowerCase();
8+
>x.toLowerCase() : any
9+
>x.toLowerCase : any
10+
>x : Promise<number>
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f(x: Promise<number>) {
2+
x.toLowerCase();
3+
}

0 commit comments

Comments
 (0)