Merge pull request #23050 from gagoman/fix/22923

Fix issue #22923
This commit is contained in:
Mohamed Hegazy 2018-04-06 09:31:43 -07:00 committed by GitHub
commit da312398f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 154 additions and 5 deletions

View File

@ -16616,12 +16616,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));
}

View File

@ -2012,7 +2012,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

View File

@ -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'?
}

View File

@ -0,0 +1,10 @@
//// [nonexistentPropertyAvailableOnPromisedType.ts]
function f(x: Promise<string>) {
x.toLowerCase();
}
//// [nonexistentPropertyAvailableOnPromisedType.js]
function f(x) {
x.toLowerCase();
}

View File

@ -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))
}

View File

@ -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
}

View File

@ -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>'.
}

View File

@ -0,0 +1,10 @@
//// [nonexistentPropertyOnUnion.ts]
function f(x: string | Promise<string>) {
x.toLowerCase();
}
//// [nonexistentPropertyOnUnion.js]
function f(x) {
x.toLowerCase();
}

View File

@ -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))
}

View File

@ -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
}

View File

@ -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>'.
}

View File

@ -0,0 +1,10 @@
//// [nonexistentPropertyUnavailableOnPromisedType.ts]
function f(x: Promise<number>) {
x.toLowerCase();
}
//// [nonexistentPropertyUnavailableOnPromisedType.js]
function f(x) {
x.toLowerCase();
}

View File

@ -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))
}

View File

@ -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
}

View File

@ -0,0 +1,3 @@
function f(x: Promise<string>) {
x.toLowerCase();
}

View File

@ -0,0 +1,3 @@
function f(x: string | Promise<string>) {
x.toLowerCase();
}

View File

@ -0,0 +1,3 @@
function f(x: Promise<number>) {
x.toLowerCase();
}