mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
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
@ -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…
x
Reference in New Issue
Block a user