Skip to content

Compatibility check for nested conditional types allows unknown properties in second level of nesting #28616

Closed
@timargra

Description

@timargra

TypeScript Version: 3.2.0-dev.20181117

Code

export type View<T> = { [K in keyof T]: T[K] extends object ? boolean | View<T[K]> : boolean };

interface TypeC {
    foo: string;
    bar: string;
}

interface TypeB {
    foo: string,
    bar: TypeC
}

interface TypeA {
    foo: string,
    bar: TypeB,
}

let test: View<TypeA>;

test = { foo: true, bar: true, boo: true } // error TS2322: Type '{ foo: true; bar: true; boo: boolean; }' is not assignable to type 'View<TypeA>'. Object literal may only specify known properties, and 'boo' does not exist in type 'View<TypeA>'.

test = { foo: true, bar: { foo: true, bar: true, boo: true } } // error TS2322:  Type '{ foo: true; bar: { foo: true; bar: true; boo: boolean; }; }' is not assignable to type 'View<TypeA>'. Types of property 'bar' are incompatible. Type '{ foo: true; bar: true; boo: boolean; }' is not assignable to type 'boolean | View<TypeB>'. Object literal may only specify known properties, and 'boo' does not exist in type 'boolean | View<TypeB>'.

Expected behavior:

test = { foo: true, bar: { foo: true, bar: { foo: true, bar: true, boo: true } } } // error TS2322:  Type '{ foo: true; bar: { foo: true; bar: { foo: true; bar: true; boo: true }; }; }' is not assignable to type 'View<TypeA>'. Types of property 'bar' are incompatible...

Actual behavior:

test = { foo: true, bar: { foo: true, bar: { foo: true, bar: true, boo: true } } } // no error!

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions