Merge pull request #18955 from Microsoft/binding-element-with-parent-type-any-is-any

Binding element with parent type any is of type any
This commit is contained in:
Nathan Shively-Sanders 2017-10-04 16:03:44 -07:00 committed by GitHub
commit 8b2a219dd4
9 changed files with 23 additions and 26 deletions

View File

@ -4151,13 +4151,13 @@ namespace ts {
if (parentType === unknownType) {
return unknownType;
}
// If no type was specified or inferred for parent, or if the specified or inferred type is any,
// infer from the initializer of the binding element if one is present. Otherwise, go with the
// undefined or any type of the parent.
if (!parentType || isTypeAny(parentType)) {
if (declaration.initializer) {
return checkDeclarationInitializer(declaration);
}
// If no type was specified or inferred for parent,
// infer from the initializer of the binding element if one is present.
// Otherwise, go with the undefined type of the parent.
if (!parentType) {
return declaration.initializer ? checkDeclarationInitializer(declaration) : parentType;
}
if (isTypeAny(parentType)) {
return parentType;
}
@ -4183,9 +4183,6 @@ namespace ts {
// computed properties with non-literal names are treated as 'any'
return anyType;
}
if (declaration.initializer) {
getContextualType(declaration.initializer);
}
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
// or otherwise the type of the string index signature.

View File

@ -28,9 +28,9 @@ var [a0, a1]: any = undefined;
>undefined : undefined
var [a2 = false, a3 = 1]: any = undefined;
>a2 : boolean
>a2 : any
>false : false
>a3 : number
>a3 : any
>1 : 1
>undefined : undefined

View File

@ -28,9 +28,9 @@ var [a0, a1]: any = undefined;
>undefined : undefined
var [a2 = false, a3 = 1]: any = undefined;
>a2 : boolean
>a2 : any
>false : false
>a3 : number
>a3 : any
>1 : 1
>undefined : undefined

View File

@ -28,9 +28,9 @@ var [a0, a1]: any = undefined;
>undefined : undefined
var [a2 = false, a3 = 1]: any = undefined;
>a2 : boolean
>a2 : any
>false : false
>a3 : number
>a3 : any
>1 : 1
>undefined : undefined

View File

@ -39,7 +39,7 @@ var {1: b3} = { 1: "string" };
>"string" : "string"
var {b4 = 1}: any = { b4: 100000 };
>b4 : number
>b4 : any
>1 : 1
>{ b4: 100000 } : { b4: number; }
>b4 : number

View File

@ -39,7 +39,7 @@ var {1: b3} = { 1: "string" };
>"string" : "string"
var {b4 = 1}: any = { b4: 100000 };
>b4 : number
>b4 : any
>1 : 1
>{ b4: 100000 } : { b4: number; }
>b4 : number

View File

@ -1,20 +1,20 @@
=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts ===
const {
a = 1,
>a : 1
>a : any
>1 : 1
b = 2,
>b : 2
>b : any
>2 : 2
c = b, // ok
>c : 2
>b : 2
>c : any
>b : any
d = a, // ok
>d : 1
>a : 1
>d : any
>a : any
e = f, // error
>e : any

View File

@ -77,7 +77,7 @@ class C {
}
function foobar({ bar={}, ...opts }: any = {}) {
>foobar : ({ bar, ...opts }?: any) => void
>bar : {}
>bar : any
>{} : {}
>opts : any
>{} : {}

View File

@ -77,7 +77,7 @@ class C {
}
function foobar({ bar={}, ...opts }: any = {}) {
>foobar : ({ bar, ...opts }?: any) => void
>bar : {}
>bar : any
>{} : {}
>opts : any
>{} : {}