diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 307680d941ef1..f4ddd1af91d6b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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)); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index bbc00e6fbc621..f7d3e4b09c3d8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 diff --git a/tests/baselines/reference/missingPropertyOfPromise.errors.txt b/tests/baselines/reference/missingPropertyOfPromise.errors.txt new file mode 100644 index 0000000000000..f40c269e892e9 --- /dev/null +++ b/tests/baselines/reference/missingPropertyOfPromise.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/missingPropertyOfPromise.ts(2,7): error TS2570: Property 'toLowerCase' does not exist on type 'Promise'. Did you forget to await the 'Promise'? + + +==== tests/cases/compiler/missingPropertyOfPromise.ts (1 errors) ==== + function f(x: Promise) { + x.toLowerCase(); + ~~~~~~~~~~~ +!!! error TS2570: Property 'toLowerCase' does not exist on type 'Promise'. Did you forget to await the 'Promise'? + } + \ No newline at end of file diff --git a/tests/baselines/reference/missingPropertyOfPromise.js b/tests/baselines/reference/missingPropertyOfPromise.js new file mode 100644 index 0000000000000..c21d6b257dc6d --- /dev/null +++ b/tests/baselines/reference/missingPropertyOfPromise.js @@ -0,0 +1,10 @@ +//// [missingPropertyOfPromise.ts] +function f(x: Promise) { + x.toLowerCase(); +} + + +//// [missingPropertyOfPromise.js] +function f(x) { + x.toLowerCase(); +} diff --git a/tests/baselines/reference/missingPropertyOfPromise.symbols b/tests/baselines/reference/missingPropertyOfPromise.symbols new file mode 100644 index 0000000000000..009e878fa06c6 --- /dev/null +++ b/tests/baselines/reference/missingPropertyOfPromise.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/missingPropertyOfPromise.ts === +function f(x: Promise) { +>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)) +} + diff --git a/tests/baselines/reference/missingPropertyOfPromise.types b/tests/baselines/reference/missingPropertyOfPromise.types new file mode 100644 index 0000000000000..ec7bbc68ac729 --- /dev/null +++ b/tests/baselines/reference/missingPropertyOfPromise.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/missingPropertyOfPromise.ts === +function f(x: Promise) { +>f : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.toLowerCase(); +>x.toLowerCase() : any +>x.toLowerCase : any +>x : Promise +>toLowerCase : any +} + diff --git a/tests/cases/compiler/missingPropertyOfPromise.ts b/tests/cases/compiler/missingPropertyOfPromise.ts new file mode 100644 index 0000000000000..476f4ac563617 --- /dev/null +++ b/tests/cases/compiler/missingPropertyOfPromise.ts @@ -0,0 +1,3 @@ +function f(x: Promise) { + x.toLowerCase(); +}