Skip to content

A bug of type system? #18909

Closed
Closed
@xiaocaibird

Description

@xiaocaibird
   type base = {
        a: {
            a1: string,
            a2: string
        },
        b: {
            b1: string,
            b2: string
        }
        c: {
            c1: string,
            c2: string
        }
    }
    type key1 = keyof base;     //"a" | "b" | "c"
    type key2 = {[p in key1]: keyof base[p]}       //{ a: "a1" | "a2"; b: "b1" | "b2"; c: "c1" | "c2"; }



    type strictKeys<T extends {[p in K]: T[p]}, K extends string> = T;
    type obj1 = {
        a: {
            a1: string,
            a2: string
        },
        b: {
            b1: string,
            b2: string
        }
    }
    type obj2 = {
        a: {
            a1: string,
            a2: string
        },
        b: {
            b1: string,
            b2: string
        }
        c: {
            c1: string,
            c2: string
        }
    }

    type T1 = {
        [k in keyof obj1 & key1]: strictKeys<obj1[k], key2[k]>
    }   // is ok

    type T2 = {
        [k in keyof obj2 & key1]: strictKeys<obj2[k], key2[k]>
    }  // error

    type T3 = {
        a: strictKeys<obj2['a'], key2['a']>,
        b: strictKeys<obj2['b'], key2['b']>,        
        c: strictKeys<obj2['c'], key2['c']>,                
    }  // is ok

When i delete 'a' or 'b' or 'c' from 'obj2', 'T2' is ok.
Why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions