Skip to content

Fix issue #22923 #23050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}