Merge pull request #15257 from Microsoft/unknown-properties-are-assignable-to-Object-in-union
Unknown properties are assignable to `Object` in union
This commit is contained in:
commit
2e43c869b4
5 changed files with 38 additions and 1 deletions
|
@ -8708,7 +8708,7 @@ namespace ts {
|
|||
if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) {
|
||||
const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes);
|
||||
if ((relation === assignableRelation || relation === comparableRelation) &&
|
||||
(target === globalObjectType || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
|
||||
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
|
||||
return false;
|
||||
}
|
||||
for (const prop of getPropertiesOfObjectType(source)) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
//// [unknownPropertiesAreAssignableToObjectUnion.ts]
|
||||
const x: Object | string = { x: 0 };
|
||||
const y: Object | undefined = { x: 0 };
|
||||
|
||||
|
||||
//// [unknownPropertiesAreAssignableToObjectUnion.js]
|
||||
var x = { x: 0 };
|
||||
var y = { x: 0 };
|
|
@ -0,0 +1,11 @@
|
|||
=== tests/cases/compiler/unknownPropertiesAreAssignableToObjectUnion.ts ===
|
||||
const x: Object | string = { x: 0 };
|
||||
>x : Symbol(x, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 0, 5))
|
||||
>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 0, 28))
|
||||
|
||||
const y: Object | undefined = { x: 0 };
|
||||
>y : Symbol(y, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 1, 5))
|
||||
>Object : Symbol(Object, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(unknownPropertiesAreAssignableToObjectUnion.ts, 1, 31))
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
=== tests/cases/compiler/unknownPropertiesAreAssignableToObjectUnion.ts ===
|
||||
const x: Object | string = { x: 0 };
|
||||
>x : string | Object
|
||||
>Object : Object
|
||||
>{ x: 0 } : { x: number; }
|
||||
>x : number
|
||||
>0 : 0
|
||||
|
||||
const y: Object | undefined = { x: 0 };
|
||||
>y : Object | undefined
|
||||
>Object : Object
|
||||
>{ x: 0 } : { x: number; }
|
||||
>x : number
|
||||
>0 : 0
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// @strictNullChecks: true
|
||||
const x: Object | string = { x: 0 };
|
||||
const y: Object | undefined = { x: 0 };
|
Loading…
Reference in a new issue