Skip to content

Combination of intersections/partials causes invalid nested object type to not report errorΒ #51043

Closed
@dlane-stripe

Description

@dlane-stripe

Bug Report

πŸ”Ž Search Terms

partial nested object type

πŸ•— Version & Regression Information

  • This changed between versions 4.5.5 and 4.6.4. It reproduces in all versions since 4.6.4 (including nightly)

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type OverridesInput = {
    someProp?: 'A' | 'B'
}

const foo: Partial<{something: any}> & {variables: {
    overrides?: OverridesInput;
} & Partial<{
    overrides?: OverridesInput;
}>} = {variables: {overrides: false}};

πŸ™ Actual behavior

There is no error on the overrides field in the object. Changing the type of foo slightly (removing one of the intersections) causes the error to appear correctly, but this unique combination of types produces no error. Does not matter what the contents of OverridesInput is, nor what the content inside the outer partial (currently {something: any}) is. Additionally, the following all produce the error correctly:

type OverridesInput = {
    someProp?: 'A' | 'B'
}

const foo: {variables: {
    overrides?: OverridesInput;
} & Partial<{
    overrides?: OverridesInput;
}>} = {variables: {overrides: false}};
type OverridesInput = {
    someProp?: 'A' | 'B'
}

const foo: Partial<{something: any}> & {variables: {
    overrides?: OverridesInput;
}} = {variables: {overrides: false}};
type OverridesInput = {
    someProp?: 'A' | 'B'
}

const foo: Partial<{something: any}> & {variables: Partial<{
    overrides?: OverridesInput;
}>} = {variables: {overrides: false}};

πŸ™‚ Expected behavior

There should be an error on the overrides field of the object since false is not assignable to OverridesInput | undefined.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions