TypeScript/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration8.ts
Nathan Shively-Sanders 5c2eeb20b1
Destructuring declaration prefers type annotation type (#25282)
* Destructuring declaration prefers type annotation type

Previously, getTypeForBindingElement would always union the declarations type and
the type of the default initializer. Now, if the declaration has a type
annotation, it does not union with the initializer type. The type
annotation's type is the one used.

* Small cleanup in parentDeclarationHasTypeAnnotation

* Refactoring based on PR comments

* Combine getCombined*Flags into a single helper function

Retain the individual functions since they are used a lot.

* Remove unneeded temp
2018-06-28 10:41:38 -07:00

19 lines
388 B
TypeScript

// explicit type annotation should cause `method` to have type 'x' | 'y'
// both inside and outside `test`.
function test({
method = 'z',
nested: { p = 'c' }
}: {
method?: 'x' | 'y',
nested?: { p: 'a' | 'b' }
})
{
method
p
}
test({});
test({ method: 'x', nested: { p: 'a' } })
test({ method: 'z', nested: { p: 'b' } })
test({ method: 'one', nested: { p: 'a' } })